<template>
  <div style="background: #ffffff">
    <div class="app-container" style="background: #ffffff;  ">
      <el-form ref="form2" :model="form2" :rules="rulesht" label-width="110px">
        <el-row :gutter="20" style="margin-top: 10px;" v-loading="loading">
          <el-col :span="24">
            <el-card class="update-log">
              <el-row :gutter="10" class="mb8">
                <el-col :span="4">
                  <h5 style="font-size: 14px; color: #252B3A; font-weight: 700;margin-top: 0px;margin-bottom: 20px;">
                    客户信息</h5>
                </el-col>
                <el-col :span="20">
                  <div align="right">
                    <el-form :inline="true" label-width="68px">

                      <el-form-item label="">
                        <el-button v-if="(form2.agrType != 1) || checkPermi(['AgreementMain:agreement:bdsel'])"
                          type="primary" @click="submitForm2">确 定</el-button>
                      </el-form-item>
                    </el-form>
                  </div>
                </el-col>

              </el-row>
              <el-row>
                <el-col :span="6">
                  <el-form-item label="合同日期" prop="agrDate">
                    <el-date-picker v-model="form2.agrDate" value-format="yyyy-MM-dd" style="width:90%" type="date"
                      @change="changedate($event)" placeholder="选择日期">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="合同编号" prop="agrId">
                    <el-input style="width:90%" v-model="form2.agrId" placeholder="请输入合同编号" clearable disabled />
                  </el-form-item>
                </el-col>

                <el-col :span="6">
                  <el-form-item label="商机来源" prop="agrSjly">
                    <el-select placeholder="商机来源" style="width:90%" v-model="form2.agrSjly" clearable>
                      <el-option v-for="dict in dict.type.ht_sjly" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                    </el-select>
                  </el-form-item>

                </el-col>
                <el-col :span="6">
                  <el-form-item label="客户名称" prop="khname">
                    <el-input v-model="form2.khname" clearable placeholder="客户名称" @focus="showkh()">
                      <i slot="suffix" class="el-icon-document-copy ckh" :data-clipboard-text="form2.khname"
                        style="cursor:pointer ;" @click="copy('.ckh')"></i>
                    </el-input>
                  </el-form-item>

                </el-col>
              </el-row>
              <el-row>
                <el-col :span="6">
                  <el-form-item label="客户打款抬头" prop="agrDktt">
                    <el-input style="width:90%" v-model="form2.agrDktt" clearable placeholder="客户打款抬头">
                      <i slot="suffix" class="el-icon-camera" style="cursor:pointer ;" @click="copyfd"></i>
                    </el-input>

                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="我方收款抬头" prop="agrSkzh">
                    <el-select style="width:90%" v-model="form2.agrSkzh" clearable placeholder="我方收款抬头">
                      <el-option v-for="dict in dict.type.ht_skzh" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="一级渠道" prop="gsname">
                    <el-input v-model="form2.gsname" style="width:90%" clearable placeholder="一级渠道"
                      @focus="showsjqd(2)" @clear="cancelHb()">
                      <i slot="suffix" class="el-icon-document-copy cgsqd" :data-clipboard-text="form2.gsname"
                        style="cursor:pointer ;" @click="copy('.cgsqd')"></i>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="二级渠道" prop="sjname">
                    <el-input v-model="form2.sjname" clearable placeholder="二级渠道" @focus="showsjqd(1)" :disabled="!form2.deaId">
                      <i slot="suffix" class="el-icon-document-copy csjqd" :data-clipboard-text="form2.sjname"
                        style="cursor:pointer ;" @click="copy('.csjqd')"></i>
                    </el-input>
                  </el-form-item>
                </el-col>


              </el-row>
<!--              <el-row>-->

<!--                <el-col :span="6">-->
<!--                  <el-form-item label="下单模式" prop="agrXdms">-->
<!--                    <el-select placeholder="下单模式" style="width:90%" v-model="form2.agrXdms" clearable>-->
<!--                      <el-option v-for="dict in dict.type.ht_xdms" :key="dict.value" :label="dict.label"-->
<!--                        :value="dict.value" />-->
<!--                    </el-select>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--                <el-col :span="6">-->
<!--                  <el-form-item label="订单类型" prop="agrDdlx">-->
<!--                    <el-select placeholder="订单类型" style="width:90%" v-model="form2.agrDdlx" clearable>-->
<!--                      <el-option v-for="dict in dict.type.ht_ddlx" :key="dict.value" :label="dict.label"-->
<!--                        :value="dict.value" />-->
<!--                    </el-select>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--                <el-col :span="6">-->
<!--                  <el-form-item label="订单周期" prop="agrDdzq">-->
<!--                    <el-select placeholder="订单周期" style="width:90%" v-model="form2.agrDdzq" clearable>-->
<!--                      <el-option v-for="dict in dict.type.ht_ddzq" :key="dict.value" :label="dict.label"-->
<!--                        :value="dict.value" />-->
<!--                    </el-select>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--                <el-col :span="6">-->
<!--                  <el-form-item label="是否新客" prop="agrSfxk">-->
<!--                    <el-select placeholder="是否新客" style="width:100%" v-model="form2.agrSfxk" clearable>-->
<!--                      <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label"-->
<!--                        :value="dict.value" />-->
<!--                    </el-select>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--              </el-row>-->
              <el-row>

                <el-col :span="6">
                  <el-form-item label="下单模式" prop="agrXdms">
                    <el-select placeholder="下单模式" style="width:90%" v-model="form2.agrXdms" clearable>
                      <el-option v-for="dict in dict.type.ht_xdms" :key="dict.value" :label="dict.label"
                                 :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="订单类型" prop="agrDdlx">
                    <el-select placeholder="订单类型" style="width:90%" v-model="form2.agrDdlx" clearable>
                      <el-option v-for="dict in dict.type.ht_ddlx" :key="dict.value" :label="dict.label"
                                 :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="订单周期" prop="agrDdzq">
                    <el-select placeholder="订单周期" style="width:90%" v-model="form2.agrDdzq" clearable>
                      <el-option v-for="dict in dict.type.ht_ddzq" :key="dict.value" :label="dict.label"
                                 :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="是否新客" prop="agrSfxk">
                    <el-select placeholder="是否新客" style="width:100%" v-model="form2.agrSfxk" clearable>
                      <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label"
                                 :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
<!--                <el-col :span="6">-->
<!--                  <el-form-item label="绑定客户" prop="userId">-->
<!--                    <el-input v-model="form2.khname" clearable placeholder="客户名称" @focus="showkh()">-->
<!--                      <i slot="suffix" class="el-icon-document-copy ckh" :data-clipboard-text="form2.khname"-->
<!--                         style="cursor:pointer ;" @click="copy('.ckh')"></i>-->
<!--                    </el-input>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
                <el-col :span="6">
                  <el-form-item label="企业项目" prop="projectName">
                    <el-select placeholder="企业项目" style="width:90%" v-model="form2.projectName" clearable disabled>
                      <el-option v-for="dict in dict.type.ht_xdms" :key="dict.value" :label="dict.label"
                                 :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="华为账号" prop="accountName">
                    <el-select placeholder="华为账号" style="width:90%" v-model="form2.accountName" clearable disabled>
                      <el-option v-for="dict in dict.type.ht_ddlx" :key="dict.value" :label="dict.label"
                                 :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>

                <el-col :span="24">

                  <el-form-item label="备注" prop="mark">
                    <el-input v-model="form2.mark" type="textarea" placeholder="请输入备注" />
                  </el-form-item>
                </el-col>

              </el-row>
            </el-card>
          </el-col>
        </el-row>
        <el-row :gutter="20" style="margin-top: 10px;">
          <el-col :span="24">
            <el-card class="update-log">
              <el-tabs v-model="activeName" @tab-click="tbClick">
                <el-tab-pane label="订单管理" name="first">
                  <el-row>
                    <!-- <file-upload v-model="testfile"/> -->
<!--                    <el-upload ref="upload" :limit="10" :action="upload.url" :headers="upload.headers"-->
<!--                      :file-list="upload.fileList" :on-progress="handleFileUploadProgress" :on-remove="handleupRemove"-->
<!--                      :on-success="handleFileSuccess" :auto-upload="true" class="hide-upload-list">-->
<!--                      <el-button type="primary" plain icon="el-icon-plus" size="mini"-->
<!--                        v-if="(form2.agrType != 1) || checkPermi(['AgreementMain:agreement:bdsel'])">关联订单</el-button>-->

<!--                    </el-upload>-->
                    <el-button type="primary" plain icon="el-icon-zoom-in" style="margin-bottom: 8px" size="mini" @click="adddd">关联订单</el-button>
                  </el-row>

                  <el-row :gutter="10" class="mb8">
                    <el-col>
                      <el-table :data="customerorderListItem" height="300px" border="" v-loading="loading1"
                                :header-cell-style="{ background: '#eef1f6', color: '#606266' }">
                        <el-table-column label="订单号" align="center" prop="orderId" width="180">
                          <template slot-scope="scope">
                            <div @click="xqtc(scope.row)" style="color: cornflowerblue;cursor: pointer;">{{
                                scope.row.orderId }}</div>
                          </template>
                        </el-table-column>
                        <el-table-column label="客户帐号id" align="center" prop="customerId" v-if="false" />
                        <el-table-column label="云服务类型编码" align="center" prop="serviceTypeCode" v-if="false" />
                        <el-table-column label="产品类型" align="center" prop="serviceTypeName" />
                        <el-table-column label="订单类型" align="center" prop="orderType">
                          <template slot-scope="scope">
                            <dict-tag :options="dict.type.sys_order_type" :value="scope.row.orderType" />
                          </template>
                        </el-table-column>
                        <el-table-column label="订单状态" align="center" prop="status">
                          <template slot-scope="scope">
                            <dict-tag :options="dict.type.sys_order_state" :value="scope.row.status" />
                          </template>
                        </el-table-column>
                        <el-table-column label="客户名称/帐号" align="left" prop="userName" width="220">
                          <template slot-scope="scope">
                            <el-tooltip placement="top">
                              <div slot="content">{{ scope.row.customer }}<br />{{ scope.row.accountName }}</div>
                              <div>
                                <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{
                                    scope.row.customer
                                  }}
                                </div>
                                <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">
                                  {{ scope.row.accountName }}
                                </div>
                              </div>
                            </el-tooltip>
                          </template>
                        </el-table-column>
                        <el-table-column label="订单金额" align="right" prop="officialAmount">
                          <template slot-scope="scope">
                            {{ toFixed(scope.row.officialAmount) }}
                          </template>
                        </el-table-column>
                        <el-table-column label="实付金额" align="right" prop="amountAfterDiscount">
                          <template slot-scope="scope">
                            {{ toFixed(scope.row.amountAfterDiscount) }}
                          </template>
                        </el-table-column>
                        <el-table-column label="返点比例（%）" align="center" prop="applx" width="120">
                          <template slot-scope="scope">
                            <!-- <el-select placeholder="返点比例（%）" style="width:90%" v-model="scope.row.jeFd" clearable>
                              <el-option v-for="dict in dict.type.sys_order_fdbl" :key="dict.value" :label="dict.label"
                                :value="dict.value" />
                            </el-select> -->
                            <el-input style="width:90%" v-model="scope.row.jeFd" clearable></el-input>
                          </template>
                        </el-table-column>
                        <el-table-column label="官网价" align="center" prop="applx" width="120">
                          <template slot-scope="scope">
                            <el-input style="width:90%" v-model="scope.row.gwj" clearable></el-input>
                          </template>
                        </el-table-column>
                        <el-table-column label="成本价" align="center" prop="applx" width="120">
                          <template slot-scope="scope">
                            <el-input style="width:90%;" v-model="scope.row.cbj" clearable @change="changeJG(scope)"></el-input>
                          </template>
                        </el-table-column>
                        <el-table-column label="渠道价" align="center" prop="applx" width="120" >
                          <template slot-scope="scope">
                            <el-input style="width:90%" v-model="scope.row.qdj" clearable @change="changeJG(scope)"></el-input>
                          </template>
                        </el-table-column>
                        <el-table-column label="客户价" align="center" prop="applx" width="120">
                          <template slot-scope="scope">
                            <el-input style="width:90%" v-model="scope.row.khj" clearable></el-input>
                          </template>
                        </el-table-column>
                        <el-table-column label="订单订单来源类型" align="center" prop="sourceType" v-if="false" />
                        <el-table-column label="下单时间" align="center" prop="createTime1" v-if="false">
                          <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.createTime1, '{y}-{m}-{d} {hh}:{mm}') }}</span>
                            <!-- <span>{{ convertUTCTimeToLocalTime(scope.row.createTime1) }}</span> -->
                          </template>
                        </el-table-column>
                        <el-table-column label="支付时间" align="center" prop="paymentTime" width="120">
                          <template slot-scope="scope" >
                            <div slot="content" v-if="scope.row.serviceTypeName!='按需产品'">{{ parseTime(scope.row.paymentTime, '{y}-{m}-{d}') }}</div>
                            <div slot="content" v-if="scope.row.serviceTypeName=='按需产品'">{{ parseTime(scope.row.paymentTime, '{y}-{m}-{d}') }}<br />{{ parseTime(scope.row.paymentEndTime, '{y}-{m}-{d}') }}</div>
                          </template>


                        </el-table-column>

                        <el-table-column label="一级渠道" align="left" prop="deaname">
                          <template slot-scope="scope">
                            <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
                                 :title="scope.row.deaname">
                              {{ scope.row.deaname }}</div>
                          </template>
                        </el-table-column>

                        <el-table-column label="二级渠道" align="left">
                          <template slot-scope="scope">
                            <div :title="scope.row.realDeaName"
                                 style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"> {{
                                scope.row.realDeaName }}
                            </div>
                          </template>
                        </el-table-column>

                        <el-table-column label="返点金额" align="center" prop="jeFdsj" v-if="false">
                          <template slot-scope="scope">
                            {{ toFixed(scope.row.jeFdsj) }}
                          </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180px">
                          <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-connection" v-if="scope.row.serviceTypeName!='按需产品'"
                                       @click="xqtc(scope.row)">详情</el-button>
                            <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.serviceTypeName!='按需产品'"
                                       @click="handleDelete(scope.$index, scope.row)">移除</el-button>
                            <el-button size="mini" type="text" icon="el-icon-download" v-if="scope.row.serviceTypeName=='按需产品'&&scope.row.fujian!=null"
                                       @click="handleckfj(scope.row.fujian)">下载附件</el-button>
                            <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.serviceTypeName=='按需产品'"
                                       @click="handleordrupdate(scope.$index, scope.row)">修改</el-button>
                            <el-button size="mini" type="text" icon="el-icon-delete" v-if="scope.row.serviceTypeName=='按需产品'"
                                       @click="handleDeletes(scope.$index, scope.row)">删除</el-button>

                          </template>
                        </el-table-column>
                      </el-table>
                    </el-col>

                  </el-row>
                </el-tab-pane>

                <el-tab-pane label="拨款管理" name="second">
                  <el-row :gutter="10" class="mb8">

                    <el-col>
                      <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addtz">关联拨款</el-button>
                    </el-col>
                  </el-row>
                  <el-row :gutter="10" class="mb8">

                    <el-col>
                      <el-table v-loading="loading3" height="300px" :data="tzListItem" border=""
                                :header-cell-style="{ background: '#eef1f6', color: '#606266' }">
                        <el-table-column label="id" align="center" prop="aid" v-if="false" />
                        <el-table-column label="流水ID" align="center" prop="transId" width="180" />

                        <el-table-column label="渠道名称" align="center" width="220">
                          <template slot-scope="scope">
                            <span slot="reference" v-if="scope.row.deaname != null">

                              <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{
                                  scope.row.deaname }}</div>
                            </span>
                            <span slot="reference" v-else-if="scope.row.cname != null">

                              <div style="float: left; margin-left: 10px;">{{ scope.row.cname }}</div>
                            </span>
                            <span slot="reference" v-else>
                              <div style="float: left; margin-left: 10px;color: red;">无关联名称</div>
                            </span>
                          </template>
                        </el-table-column>
                        <el-table-column label="账号信息" align="center" prop="customerName" width="150" />
                        <el-table-column label="调帐时间" align="center" prop="operationTime" width="100">
                          <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.operationTime, "{y}-{m}-{d}") }}</span>
                          </template>
                        </el-table-column>

                        <el-table-column label="调帐金额" align="right" prop="amount" width="100" />
                        <el-table-column label="调帐类型" align="center" prop="operationType" width="100">
                          <template slot-scope="scope">
                            <dict-tag :options="dict.type.tzlx" :value="scope.row.operationType" />
                          </template>
                        </el-table-column>
                        <el-table-column label="拨款类型" align="center" prop="applx" width="100">
                          <template slot-scope="scope">
                            <el-select placeholder="调帐类型" style="width:90%" v-model="scope.row.applx" clearable>
                              <el-option v-for="dict in dict.type.tz_type" :key="dict.value" :label="dict.label"
                                         :value="dict.value" />
                            </el-select>
                          </template>
                        </el-table-column>
                        <el-table-column label="备注" align="center" prop="mark">
                          <template slot-scope="scope">
                            <el-input v-model="scope.row.mark" type="textarea" :title="scope.row.mark"
                                      placeholder="请输入备注" />
                          </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100px">
                          <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-delete"
                                       @click="handleDeletetz(scope.$index, scope.row)">移除</el-button>
                          </template>
                        </el-table-column>
                      </el-table>
                    </el-col>
                  </el-row>
                </el-tab-pane>
                <el-tab-pane label="费用管理" name="thred" v-if="false">
                  <el-table :data="costList" border="" :header-cell-style="{ background: '#eef1f6', color: '#606266' }">
                    <!-- <el-table-column type="selection" width="55" align="center" /> -->
                    <el-table-column label="费用日期" align="center" prop="costData" width="100">
                      <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.costData, '{y}-{m}-{d}') }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="费用类型" align="center" prop="costType" width="80">
                      <template slot-scope="scope">
                        <dict-tag :options="dict.type.cost_type" :value="scope.row.costType" />
                      </template>
                    </el-table-column>
                    <el-table-column label="付款方式" align="center" prop="costPayType" width="80">
                      <template slot-scope="scope">
                        <dict-tag :options="dict.type.cost_pay_type" :value="scope.row.costPayType" />
                      </template>
                    </el-table-column>
                    <!-- <el-table-column label="合同订单" align="center" prop="costContract" /> -->
                    <el-table-column label="费用金额" align="right" prop="costMoney" width="80">
                      <template slot-scope="scope">
                        {{ toFixed(scope.row.costMoney) }}
                      </template>
                    </el-table-column>
                    <el-table-column label="申请人" align="center" prop="nickName" width="80" />
                    <el-table-column label="项目事由" align="center" prop="costMatter" />

                    <el-table-column label="付款信息" align="center" prop="costPayingInformation" />

                    <el-table-column label="备注" align="center" prop="costNotes" />


                    <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
                      <template slot-scope="scope">
                        <el-button size="mini" type="text" icon="el-icon-edit" @click="findcost(2, scope.row)"
                                   v-hasPermi="['cost:cost:edit']">查看</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </el-tab-pane>
                <el-tab-pane label="流程费用" name="five">
                  <el-table v-loading="loading" :data="PaymentList"
                            :header-cell-style="{ background: '#eef1f6', color: '#606266' }" border>
                    <el-table-column label="用户" align="center" prop="payUserid" width="80" />
                    <el-table-column label="用户名称" align="center" prop="payUsername" width="80" />
                    <el-table-column label="状态" align="center" prop="payStatusName" width="80">
                      <template slot-scope="scope">
                        <!-- 1-审批中；2-已同意；3-已驳回；4-已转审；11-已退回；12-已加签；13-已同意并加签 -->
                        <el-tag v-if="scope.row.payStatus == '1.0'">
                          审批中
                        </el-tag>
                        <el-tag v-if="scope.row.payStatus == '2.0'" type="success">
                          已同意
                        </el-tag>
                        <el-tag v-if="scope.row.payStatus == '3.0'" type="danger">
                          已驳回
                        </el-tag>
                        <el-tag v-if="scope.row.payStatus == '4.0'" type="info">
                          已转审
                        </el-tag>
                        <el-tag v-if="scope.row.payStatus == '11.0'" type="danger">
                          已退回
                        </el-tag>
                        <el-tag v-if="scope.row.payStatus == '12.0'">
                          已加签
                        </el-tag>
                        <el-tag v-if="scope.row.payStatus == '13.0'" type="success">
                          已同意并加签
                        </el-tag>
                      </template>
                    </el-table-column>
                    <el-table-column label="付款确认" align="center" prop="payTime" width="110">
                      <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.row.payEnd == '1'">
                          已付款（{{ scope.row.payEnduser }}）
                        </el-tag>
                        <el-tag type="danger" v-if="scope.row.payEnd == '0'">
                          未付款
                        </el-tag>
                      </template>
                    </el-table-column>
                    <el-table-column label="订单日期" align="center" prop="payTime" width="100" />
                    <el-table-column label="付款方式" align="center" prop="payType" width="100" />
                    <el-table-column label="费用类型" align="center" prop="payCostType" width="100" />
                    <el-table-column label="关联模式" align="center" prop="payRelateType" width="100" />
                    <el-table-column label="费用金额" align="right" prop="payMoney" width="100" />
                    <el-table-column label="是否加急" align="center" prop="payJiaji" width="100" />
                    <el-table-column label="付款事由" align="left" prop="payDetails" width="300" />
                    <el-table-column label="付款信息" align="left" prop="payTxt" width="300" />

                    <el-table-column label="备注" align="left" prop="payBeizhu" width="300" />
                    <el-table-column label="单号" align="center" prop="paySpnoid" width="110" />
                    <el-table-column label="创建时间" align="center" prop="payCreatedtime" width="150" />
                    <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right"
                                     width="120">
                      <template slot-scope="scope">
                        <el-button size="mini" type="text" icon="el-icon-tickets"
                                   @click="handlefind(scope.row)">查看</el-button>
                        <!-- <el-button size="mini" type="text" icon="el-icon-refresh"
                          @click="handleref(scope.row)">刷新</el-button> -->
                      </template>
                    </el-table-column>
                  </el-table>

                </el-tab-pane>
                <el-tab-pane label="银行明细" name="four">
                  <el-table :data="bkList" border="" :header-cell-style="{ background: '#eef1f6', color: '#606266' }">
                    <el-table-column label="流水时间" align="center" prop="bDate" width="100">
                      <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.bDate, "{y}-{m}-{d}") }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="关联编码" align="center" prop="bIda" width="120" />
                    <el-table-column label="流水编号" align="center" prop="bId" width="140px">
                      <template slot-scope="scope">
                        <div style="color: rgb(114, 175, 228);cursor:pointer;" @click="handlerlA(scope.row)">{{
                            scope.row.bId }}
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column label="付款方" align="left" prop="bFkr" width="200">
                      <template slot-scope="scope">
                        <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
                             :title="scope.row.bFkr">
                          {{ scope.row.bFkr }}</div>
                      </template>
                    </el-table-column>

                    <el-table-column label="收款方" align="left" prop="bSkr" width="200">
                      <template slot-scope="scope">
                        <dict-tag :options="dict.type.ht_skzh" :value="scope.row.bSkr"
                                  style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" />
                      </template>
                    </el-table-column>
                    <el-table-column label="金额" align="right" prop="bSkje" width="80">
                      <template slot-scope="scope">
                        {{ toFixed(scope.row.bSkje) }}
                      </template>
                    </el-table-column>
                    <el-table-column label="业务员" align="center" prop="ywyName" width="80" />
                    <el-table-column label="一级渠道" align="left" prop="gsname" width="140" v-if="false">
                      <template slot-scope="scope">
                        <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
                             :title="scope.row.gsname">
                          {{ scope.row.gsname }}</div>
                      </template>
                    </el-table-column>
                    <el-table-column label="二级渠道" align="left" prop="sjname" width="140" v-if="false">
                      <template slot-scope="scope">
                        <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
                             :title="scope.row.sjname">
                          {{ scope.row.sjname }}</div>
                      </template>
                    </el-table-column>
                    <el-table-column label="合同金额" align="right" prop="dkce" width="90">
                      <template slot-scope="scope">
                        {{ toFixed(scope.row.dkce) }}
                      </template>
                    </el-table-column>
                    <el-table-column label="打款差额" align="right" prop="dkce" width="90">
                      <template slot-scope="scope">
                        {{ toFixed(scope.row.bCe) }}
                      </template>
                    </el-table-column>
                    <el-table-column label="对帐状态" align="center" prop="bType" width="100">
                      <template slot-scope="scope" prop="bType">
                        <div v-if="scope.row.bTj == 0">
                          <el-button plain>未提交</el-button>
                        </div>
                        <div v-else-if="scope.row.bTj == 1">
                          <el-button type="success" plain @click="findkh(2, scope.row)">待审核</el-button>
                        </div>
                        <dict-tag :options="dict.type.bank_type" :value="scope.row.bType" v-else />
                      </template>
                    </el-table-column>
                    <el-table-column label="备注" align="left" prop="mark">
                      <template slot-scope="scope">
                        <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
                             :title="scope.row.mark">
                          {{ scope.row.mark }}</div>
                      </template>
                    </el-table-column>
                    <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100px">
                      <template slot-scope="scope">
                        <el-button size="mini" type="text" icon="el-icon-connection"
                                   v-if="scope.row.userId != '' && scope.row.userId != null"
                                   @click="findbk(2, scope.row)">查看</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </el-tab-pane>

                <el-tab-pane label="合作伙伴" name="six">
                  <el-row :gutter="10" class="mb8">
                    <el-col :span="1.5">
                      <el-button type="primary" plain icon="el-icon-plus" size="mini"
                        v-if="(form2.agrType != 1) || checkPermi(['AgreementMain:agreement:bdsel'])"
                        @click="qxinadd">添加合作伙伴</el-button>

                    </el-col>
                  </el-row>
                  <el-table :data="qxList" border :header-cell-style="{ background: '#eef1f6', color: '#606266' }">
                    <el-table-column label="用户昵称" align="center" prop="userName" width="200" />
                    <el-table-column label="用户类型" align="center" prop="userType">
                      <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.row.userType == '00'">
                          内部业务员
                        </el-tag>
                        <el-tag type="danger" v-if="scope.row.userType == '05'">
                          外部客户
                        </el-tag>
                        <el-tag type="danger" v-if="scope.row.userType == '06'">
                          外部渠道
                        </el-tag>
                      </template>
                    </el-table-column>
                    <el-table-column label="结算类型" align="center" prop="jsType">
                      <template slot-scope="scope">
                        <el-select v-model="scope.row.jsType" style="width: 90%;" filterable placeholder="结算类型">
                          <el-option key="0" label="先返" value="0"></el-option>
                          <el-option key="1" label="关联付款流程" value="1"></el-option>
                        </el-select>
                      </template>
                    </el-table-column>
                    <el-table-column label="分润比例（%）" align="center" prop="moneyPro">
                      <template slot-scope="scope">
                        <el-input-number :controls="false" :precision="2" v-model="scope.row.moneyPro"
                          @change="frpro(scope.$index,scope.row.userType,scope.row.moneyPro)"></el-input-number>
                      </template>
                    </el-table-column>
                    <el-table-column label="分润金额(元)" align="center" prop="moneyNumber">
                      <template slot-scope="scope">
                        <el-input-number :controls="false" :precision="2" v-model="scope.row.moneyNumber"
                          @change="frmoney(scope.$index,scope.row.userType,scope.row.moneyNumber)"></el-input-number>
                      </template>
                    </el-table-column>
                    <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200"
                      v-if="!this.sdtype">
                      <template slot-scope="scope">
                        <el-button type="danger" size="small" @click="delpow(scope.row)" plain>删除</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                  <el-row style="margin-top: 80rpx;">
                    <el-col :span="4">
                      <div style="margin-top: 6px;float: left;">外部分润合计：</div>
                      <div style="color: #0151ff;margin-top: 10px;font-weight: bolder;float: left;">{{outallmoney}}
                      </div>
                    </el-col>
                    <el-col :span="4">
                      <div style="margin-top: 6px;float: left;">内部分润合计：</div>
                      <div style="color: #0151ff;margin-top: 10px;font-weight: bolder;float: left;">{{inallmoney}}</div>
                    </el-col>
                  </el-row>
                </el-tab-pane>
              </el-tabs>
            </el-card>
          </el-col>
        </el-row>
        <el-row :gutter="20" style="margin-top: 10px;">
          <el-col :span="24">
            <el-card class="update-log">
              <h5 style="font-size: 14px; color: #252B3A;  font-weight: 700;margin-top: 0px;margin-bottom: 20px;">
                毛利参数</h5>
              <el-form label-width="100px" size="mini">
                <div style="width: 100%;height: 50px;">
                  <div style="width: 24.5%;float: left;">
                    <el-form-item label="官网价" prop="gwj">
                      <el-input v-model="form2.gwj" disabled placeholder="" @input.native="form2.gwj =
                        form2.gwj.replace
                          (form2.gwj, RestrictedMoney
                            (form2.gwj))" class="jeclass" />
                    </el-form-item>
                  </div>
                  <div style="width: 24.5%;float: left;">
                    <el-form-item label="成本价" prop="cbj">
                      <el-input v-model="form2.cbj" disabled placeholder="" @input.native="form2.cbj =
                        form2.cbj.replace
                          (form2.cbj, RestrictedMoney
                            (form2.cbj))" class="jeclass" />
                    </el-form-item>
                  </div>
                  <div style="width: 24.5%;float: left;">
                    <el-form-item label="渠道价" prop="qdj">
                      <el-input v-model="form2.qdj" disabled placeholder="" @input.native="form2.qdj =
                        form2.qdj.replace
                          (form2.qdj, RestrictedMoney
                            (form2.qdj))" class="jeclass" />
                    </el-form-item>
                  </div>
                  <div style="width: 24.5%;float: left;">
                    <el-form-item label="客户价" prop="khj">

                      <el-input v-model="form2.khj" disabled placeholder="" @input.native="form2.khj =
                        form2.khj.replace
                          (form2.khj, RestrictedMoney
                            (form2.khj))" class="jeclass">

                      </el-input>
                    </el-form-item>
                  </div>

                </div>
              </el-form>
              <el-form label-width="100px" size="mini">
                <div style="width: 100%;height: 50px;">
                  <div style="width: 14%;float: left;">
                    <el-form-item label="打款金额" prop="jeDk">
                      <el-input v-model="form2.jeDk" placeholder="" @input.native="form2.jeDk =
                        form2.jeDk.replace
                          (form2.jeDk, RestrictedMoney
                            (form2.jeDk))" @change="materielExtraCostChange(form2.jeDk, 1)" class="jeclass" />
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="拨款金额" prop="jeBk">
                      <el-input v-model="form2.jeBk" placeholder="" @input.native="form2.jeBk =
                        form2.jeBk.replace
                          (form2.jeBk, RestrictedMoney
                            (form2.jeBk))" @change="materielExtraCostChange(form2.jeBk, 2)" class="jeclass" />
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="暂估返点" prop="jeFdsj">

                      <el-input v-model="form2.jeFd" placeholder="" @input.native="form2.jeFd =
                        form2.jeFd.replace
                          (form2.jeFd, RestrictedMoney
                            (form2.jeFd))" @change="materielExtraCostChange(form2.jeFd, 5)" class="jeclass">

                      </el-input>
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="返客金额" prop="jeFk">
                      <el-input v-model="form2.jeFk" placeholder="" @input.native="form2.jeFk =
                        form2.jeFk.replace
                          (form2.jeFk, RestrictedMoney
                            (form2.jeFk))" @change="materielExtraCostChange(form2.jeFk, 3)" class="jeclass" />
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="返渠金额" prop="jeFq">
                      <el-input v-model="form2.jeFq" placeholder="" @input.native="form2.jeFq =
                        form2.jeFq.replace
                          (form2.jeFq, RestrictedMoney
                            (form2.jeFq))" @change="materielExtraCostChange(form2.jeFq, 4)" class="jeclass" />
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="项目毛利" prop="xmMl" class="jeclass">
                      <el-input v-model="form2.xmMl" />
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="暂估毛利" prop="sjMl" class="jeclass">
                      <el-input v-model="form2.sjMl" />
                    </el-form-item>
                  </div>

                </div>
                <div style="width: 100%;height: 50px;">
                  <div style="width: 14%;float: left;">
                    <el-form-item label="打款差额">
                      <h5
                        style="color: black; font-weight: bold;margin-top: 7px;margin-bottom: 0px; color:red; font-size: 16px;position: absolute;right: 0%;">
                        {{ toFixed(this.form2.jeNfbl) }}</h5>
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="调帐金额" prop="tzje">
                      <h5
                        style="color: black; font-weight: bold;margin-top: 7px;margin-bottom: 0px; color:blue; font-size: 16px;position: absolute;right: 0%;">
                        {{ tzjeshow }}</h5>
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="返客金额" prop="">
                      <h5
                        style="color: black; font-weight: bold;margin-top: 7px;margin-bottom: 0px; color:blue; font-size: 16px;position: absolute;right: 0%;">
                        {{ fkjeshow }}
                      </h5>
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="返渠金额" prop="">
                      <h5
                        style="color: black; font-weight: bold;margin-top: 7px;margin-bottom: 0px; color:blue; font-size: 16px;position: absolute;right: 0%;">
                        {{ fqjeshow }}
                      </h5>
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="返点金额" prop="zfje">
                      <h5
                        style="color: black; font-weight: bold;margin-top: 7px;margin-bottom: 0px; color:rgb(0, 162, 255); font-size: 16px;position: absolute;right: 0%;">
                        {{ zgfdshow }}</h5>
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="订单金额" prop="zfje">
                      <h5
                        style="color: black; font-weight: bold;margin-top: 7px;margin-bottom: 0px; color:red; font-size: 16px;position: absolute;right: 0%;">
                        {{ zfjeshow }}</h5>
                    </el-form-item>
                  </div>
                  <div style="width: 14%;float: left;">
                    <el-form-item label="毛利润率" prop="mLlr" class="jeclass">
                      <h5
                        style="color: black; font-weight: bold;margin-top: 7px;margin-bottom: 0px; color:rgb(183, 18, 248); font-size: 16px;position: absolute;right: 0%;">
                        {{ mLlr }}</h5>
                    </el-form-item>
                  </div>
                </div>
              </el-form>

              <!-- <el-row>
                <el-col :span="4">
                  <el-form-item label="项目毛利">
                    <h5 style="color: rgb(99, 10, 243); font-weight: bold;margin-top: 7px;margin-bottom: 0px; font-size: 16px;position: absolute;
    right: 0%;">
                      {{ xmmlshow }}</h5>
                  </el-form-item>
                </el-col>
                <el-col :span="4">
                  <el-form-item label="实际毛利">
                    <h5 style="color: rgb(99, 10, 243); font-weight: bold;margin-top: 7px;margin-bottom: 0px;  font-size: 16px;position: absolute;
    right: 0%;">
                      {{ sjmlshow }}</h5>
                  </el-form-item>
                </el-col>
              </el-row> -->
              <el-divider><i class="el-icon-arrow-down"></i></el-divider>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="" prop="">
                    <h5 style="color: black; font-weight: bold;margin-top: 7px;margin-bottom: 0px; color:blue; font-size: 16px;position: absolute;
    right: 0%;">
                    </h5>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <div align="center">
                    <el-button type="primary" plain icon="el-icon-finished" @click="clickjs" title="计算"></el-button>
                    <el-button type="primary" @click="submitForm2"
                               v-if="(form2.agrType != 1) || checkPermi(['AgreementMain:agreement:bdsel'])">确 定</el-button>
                  </div>
                </el-col>
                <el-col :span="4">

                </el-col>

              </el-row>
            </el-card>
          </el-col>
        </el-row>
        <el-row :gutter="20" style="margin-top: 10px;">
          <el-col :span="24">
            <el-card class="update-log">
              <h5 style="font-size: 14px; color: #252B3A; font-weight: 700;margin-top: 0px;margin-bottom: 30px;">
                审核流程责任人签字</h5>
              <el-form ref="form2" :model="form2" label-width="80px">
                <el-row>
                  <el-col :span="4">
                    <el-form-item label="业务员" prop="userId">
                      <!-- <el-input style="width:90%" placeholder="BD销售" clearable v-model="form2.ywyName" disabled /> -->
                      <el-select v-model="form2.userId" style="width: 90%;" filterable placeholder="业务员" clearable>
                        <el-option v-for="item in ywyOptions" :key="item.userId" :label="item.nickName"
                                   :value="item.userId.toString()"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="SA技术" prop="jsuserId">
                      <el-select v-model="form2.jsuserId" style="width: 90%;" filterable placeholder="SA技术" clearable>
                        <el-option v-for="item in jsyOption" :key="item.userId" :label="item.nickName"
                                   :value="item.userId.toString()"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="拨款人" prop="bkuserId">
                      <!-- <el-input style="width:90%" placeholder="BD销售" clearable v-model="form2.ywyName" disabled /> -->
                      <el-select v-model="form2.bkuserId" style="width: 90%;" filterable placeholder="拨款人" clearable>
                        <el-option v-for="item in BkOptions" :key="item.userId" :label="item.nickName"
                                   :value="item.userId.toString()"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="下单人" prop="xduserId">
                      <!-- <el-input style="width:90%" placeholder="BD销售" clearable v-model="form2.ywyName" disabled /> -->
                      <el-select v-model="form2.xduserId" style="width: 90%;" filterable placeholder="下单人" clearable>
                        <el-option v-for="item in XdOptions" :key="item.userId" :label="item.nickName"
                                   :value="item.userId.toString()"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="初审" prop="sh1userId">
                      <el-select v-model="form2.sh1userId" style="width: 90%;" filterable placeholder="初审人" clearable>
                        <el-option v-for="item in sh1Options" :key="item.userId" :label="item.nickName"
                                   :value="item.userId.toString()"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="终审" prop="sh2userId">
                      <el-select v-model="form2.sh2userId" style="width: 90%;" filterable placeholder="终审人" clearable>
                        <el-option v-for="item in sh2Options" :key="item.userId" :label="item.nickName"
                                   :value="item.userId.toString()"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </el-card>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 订单选择弹窗测试 -->
    <el-dialog :title="titleord" :visible.sync="openord" width="1300px" append-to-body v-dialogDrag v-if="openord">
      <el-form :model="queryParamsord" ref="queryForm" size="small" :inline="true" v-show="showSearch"
        label-width="68px">
        <!-- <el-form-item label="客户名称" prop="name3">
          <el-input style="width:90%" v-model="form2.name3" clearable size="small " placeholder="客户名称"
            @focus="showkh()" />
        </el-form-item> -->

        <el-form-item label="订单编号" prop="orderId">
          <el-input style="width: 200px" v-model="queryParamsord.orderId" placeholder="请输入订单号" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="订单时间">

          <el-date-picker v-model="dateRange[0]" type="date" value-format="yyyy-MM-dd" placeholder="开始时间">
          </el-date-picker>

        </el-form-item>
        <el-form-item label="">
          <span>至</span>
        </el-form-item>
        <el-form-item label="">

          <el-date-picker v-model="dateRange[1]" type="date" value-format="yyyy-MM-dd" placeholder="结束时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button></el-form-item>
      </el-form>
      <el-form label-width="80px">
        <el-table v-loading="loading" style="overflow: auto; " height="400px" :data="customerorderListord"
          @selection-change="handleSelectionChange1" border=""
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }" @row-click="handleClickTableRow"
          ref="fileTable">
          <el-table-column type="selection" width="55" align="center" :selectable="checkSelect" />
          <el-table-column label="订单编号" align="center" prop="orderId" width="160" />

          <el-table-column label="云服务类型名称" align="center" prop="serviceTypeName" />

          <el-table-column label="订单类型" align="center" prop="orderType" width="80">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_order_type" :value="scope.row.orderType" />
            </template>
          </el-table-column>
          <el-table-column label="订单状态" align="center" prop="status" width="80">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_order_state" :value="scope.row.status" />
            </template>
          </el-table-column>
          <el-table-column label="订单金额" align="right" prop="officialAmount">
            <template slot-scope="scope">
              {{ toFixed(scope.row.officialAmount) }}
            </template>
          </el-table-column>
          <el-table-column label="实付金额" align="right" prop="amountAfterDiscount">
            <template slot-scope="scope">
              {{ toFixed(scope.row.amountAfterDiscount) }}
            </template>
          </el-table-column>

          <el-table-column label="支付时间" align="center" prop="paymentTime" width="120">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.paymentTime, '{y}-{m}-{d} {hh}:{mm}') }}</span>
              <!-- <span>{{ convertUTCTimeToLocalTime(scope.row.paymentTime) }}</span> -->
            </template>
          </el-table-column>
          <el-table-column label="返点金额(¥)" align="center" prop="jeFdsj" v-if="false">
            <template slot-scope="scope">
              {{ toFixed(scope.row.jeFdsj) }}
            </template>
          </el-table-column>
          <el-table-column label="客户名称/帐号" align="left" prop="userName" width="120">
            <template slot-scope="scope">
              <el-tooltip placement="top">
                <div slot="content">{{ scope.row.customer }}<br />{{ scope.row.accountName }}</div>
                <div>
                  <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{ scope.row.customer }}
                  </div>
                  <!-- <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">
                    {{ scope.row.accountName }}
                  </div> -->
                </div>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column label="关联渠道" align="left" prop="deaname">
            <template slot-scope="scope">
              <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" :title="scope.row.deaname">
                {{ scope.row.deaname }}</div>
            </template>
          </el-table-column>
          <el-table-column label="关联合同" align="center" prop="flag">

          </el-table-column>
        </el-table>

        <pagination v-show="totalord > 0" :total="totalord" :page.sync="queryParamsord.pageNum"
          :limit.sync="queryParamsord.pageSize" @pagination="getListord" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ImportClick">确 定</el-button>
        <el-button @click="cancelord">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 用户选择弹窗测试 -->
    <el-dialog :title="titleqx" width="400px" append-to-body :visible.sync="openqx">
      <el-form :model="qxform" ref="qxform" size="small" label-width="108px">
        <el-form-item label="业务员类型">
          <el-radio-group v-model="qxform.type" @change="radiochange">
            <el-radio label="0">内部业务员</el-radio>
            <el-radio label="1">外部业务员</el-radio>

          </el-radio-group>

        </el-form-item>
        <el-form-item label="选择业务员">
          <el-select v-model="qxform.userId" @change="handleChangeuser" style="width: 90%;" filterable placeholder="业务员"
            clearable>
            <el-option v-for="item in ywyOptions" :key="item.userId" :label="item.nickName"
              :value="item.userId.toString()"></el-option>
          </el-select>
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitqx">确 定</el-button>
        <el-button @click="cancelqx">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 选择客户弹窗测试 -->
    <el-dialog :title="titlekh" :visible.sync="openkh" width="1000px" append-to-body>
      <el-form :model="queryParamsKh" ref="queryFormKh" size="small" :inline="true" label-width="100px"
        @submit.native.prevent>
        <el-form-item label="客户名称" prop="nickName">
          <el-input v-model="queryParamsKh.nickName" placeholder="请输入客户名称" clearable v-on:input="handleKhQuery"
            @keyup.enter.native="handleKhQuery" />
        </el-form-item>
        <el-form-item label="联系人名称" prop="contactsName">
          <el-input v-model="queryParamsKh.contactsName" placeholder="请输入客户名称" clearable v-on:input="handleKhQuery"
                    @keyup.enter.native="handleKhQuery" />
        </el-form-item>
        <el-form-item label="联系人手机号" prop="phonenumber">
          <el-input v-model="queryParamsKh.phonenumber" placeholder="请输入客户名称" clearable v-on:input="handleKhQuery"
                    @keyup.enter.native="handleKhQuery" />
        </el-form-item>
        <el-form-item label="关联伙伴" prop="createBy">
          <el-input v-model="queryParamsKh.createBy" placeholder="请输入客户名称" clearable v-on:input="handleKhQuery"
                    @keyup.enter.native="handleKhQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleKhQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQueryKh">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form label-width="80px">
        <el-table v-loading="loading" class="clicktable" style="overflow: auto; " height="400px" :data="khList"
          @selection-change="handleSelectionChangeKh" @row-click="handleClickTableRowA" ref="fileTableA">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="客户名称" align="center" prop="nickName" />
          <el-table-column label="联系人姓名" align="center" prop="contactsName" />
          <el-table-column label="联系人手机号" align="center" prop="phonenumber" />
          <el-table-column label="关联伙伴" align="center" prop="createBy" />
          <el-table-column label="企业项目" align="center" prop="remark" />
        </el-table>
        <pagination v-show="totalkh > 0" :total="totalkh" :page.sync="queryParamsKh.pageNum"
          :limit.sync="queryParamsKh.pageSize" @pagination="getListKh" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="khClick">确 定</el-button>
        <el-button @click="khcancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 分配渠道弹窗测试 -->
    <el-dialog :title="titleqd" :visible.sync="openqd" width="1000px" append-to-body>
      <el-form :model="queryParamsQd" ref="queryFormQd" size="small" :inline="true" label-width="68px"
        @submit.native.prevent>
        <el-form-item label="渠道名称" prop="deaName">
          <el-input v-model="queryParamsHb.nickName" placeholder="请输入渠道名称" clearable v-on:input="handleQdQuery"
            @keyup.enter.native="handleQdQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQdQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQueryQd">重置</el-button>
          <el-button icon="el-icon-user" size="mini" @click="handleMyself" v-if="myself">选择自己</el-button>
<!--          <el-button type="success" icon="el-icon-add" size="mini" @click="handleAdd" v-if="sjbtshow">添加二级渠道</el-button>-->
        </el-form-item>
      </el-form>
      <el-form label-width="80px">
        <el-table v-loading="loading" style="overflow: auto; " height="400px" :data="dealerList"
          @selection-change="handleSelectionChangeQd" @row-click="handleClickTableRowB" ref="fileTableB">
          <el-table-column type="selection" width="55" align="center" />
<!--          <el-table-column label="渠道编号" align="center" prop="deaId" width="200" />-->
<!--          <el-table-column label="渠道名称" align="left" prop="deaName" width="300" />-->
<!--          <el-table-column label="关联时间" align="left" prop="associatedOn" />-->
<!--          &lt;!&ndash; <el-table-column label="帐号" align="center" prop="deaUser"  /> &ndash;&gt;-->
<!--          <el-table-column label="渠道类型" align="center" prop="accountIn" width="250">-->
<!--            <template slot-scope="scopes">-->

<!--              <el-tag v-if="scopes.row.accountIn == 1" type="danger">实际渠道</el-tag>-->
<!--              <el-tag v-else>华为渠道</el-tag>-->


<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column label="用户编号" align="center" width="120"  key="userId" prop="userId"/>
          <el-table-column label="伙伴账号" align="center" width="120" key="userName" prop="userName"
                           :show-overflow-tooltip="true" />
          <el-table-column label="伙伴名称" align="center" width="150" key="nickName" prop="nickName"
                           :show-overflow-tooltip="true" />
          <el-table-column label="分类" align="center" width="150" key="deptName" prop="dept.deptName"
                           :show-overflow-tooltip="true" />
          <!-- <el-table-column label="伙伴手机" align="center" key="phonenumber" prop="phonenumber" v-if="columns[4].visible"
            width="120" /> -->
          <el-table-column label="状态" align="center" width="100" key="status">
            <template slot-scope="scope">
              <el-switch v-model="scope.row.status" active-value="0" inactive-value="1"
                         disabled></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="类型" align="center" prop="usertype" width="100">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.usertype=='05'" type="info" style="margin-left: 3px;">客户</el-tag>
              <el-tag v-else-if="scope.row.usertype=='06'" type="success" style="margin-left: 3px;">渠道</el-tag>
            </template>

          </el-table-column>
          <el-table-column label="分配人" align="center" prop="wecomName" >

          </el-table-column>
<!--          <el-table-column label="角色" align="center" prop="roles" width="100">-->
<!--            <template slot-scope="scopes">-->
<!--              <el-row>-->
<!--                <el-col :span="1.5" v-for="(btn, index) in scopes.row.roles" :key="index">-->
<!--                  <el-tag v-if="btn.roleId==1" type="danger" style="margin-left: 3px;">{{ btn.roleName }}</el-tag>-->
<!--                  <el-tag v-else-if="btn.roleId==3" type="success" style="margin-left: 3px;">{{ btn.roleName }}</el-tag>-->
<!--                  <el-tag v-else-if="btn.roleId==7" type="info" style="margin-left: 3px;">{{ btn.roleName }}</el-tag>-->
<!--                  <el-tag v-else-if="btn.roleId==9" type="warning" style="margin-left: 3px;">{{ btn.roleName }}</el-tag>-->
<!--                  <el-tag   style="margin-left: 3px;" v-else>{{ btn.roleName }}</el-tag>-->

<!--                </el-col>-->
<!--              </el-row>-->
<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column label="客户列表" align="center" key="createBy" prop="createBy" width="120" show-overflow-tooltip/>
<!--          <el-table-column label="创建时间" align="center" width="150" prop="createTime" v-if="columns[6].visible">-->
<!--            <template slot-scope="scope">-->
<!--              <span>{{ parseTime(scope.row.createTime) }}</span>-->
<!--            </template>-->
<!--          </el-table-column>-->
        </el-table>
        <pagination v-show="totalqd > 0" :total="totalqd" :page.sync="queryParamsQd.pageNum"
          :limit.sync="queryParamsQd.pageSize" @pagination="getListDea" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="qdClick" v-if="sjbtshow">确 定</el-button>
        <el-button type="primary" @click="gsqdClick" v-if="gsbtshow">确 定</el-button>
        <el-button @click="cancelqd">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加实际渠道 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" @submit.native.prevent>
        <el-row>
          <el-col :span="12">
            <el-form-item label="渠道编码" prop="deaCode">
              <el-input v-model="form.deaCode" placeholder="渠道编码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="渠道类型" prop="deaType">
              <el-select placeholder="渠道类型" style="width:100%" v-model="deaType" clearable>
                <el-option v-for="dict in dict.type.dea_type" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="渠道名称" prop="deaName">
          <el-input v-model="form.deaName" placeholder="请输入渠道名称" />
        </el-form-item>
        <el-form-item label="经销商ID" prop="deaId" v-if="false">
          <el-input v-model="form.deaId" placeholder="请输入经销商名称" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系人" prop="deaPeople">
              <el-input v-model="form.deaPeople" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="deaTel">
              <el-input v-model="form.deaTel" placeholder="请输入手机号码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="邮箱" prop="deaEmail">
              <el-input v-model="form.deaEmail" placeholder="请输入邮箱" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="deaAddress">
          <el-input v-model="form.deaAddress" type="textarea" placeholder="请输入公司及开票信息" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--详情弹窗-->
    <el-dialog title="订单详情" :visible.sync="openxq" width="85%" append-to-body :class="$style.ElDialog" v-if="true">
      <orderxx :key="deaval.orderId" :oid="deaval.orderId" :opid="deaval.indirectPartnerId"></orderxx>
    </el-dialog>
    <!-- 选择调帐弹窗 -->
    <el-dialog :title="titletz" :visible.sync="opentz" width="1000px" append-to-body v-dialogDrag v-if="opentz">
      <el-form :model="queryParamsTz" ref="queryFormTz" size="small" :inline="true" label-width="68px"
        @submit.native.prevent>
        <el-form-item label="拨款时间">
          <el-date-picker v-model="dateRangetz[0]" type="date" value-format="yyyy-MM-dd" placeholder="开始时间"
            style="width: 130px !important;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="">
          <span>至</span>
        </el-form-item>
        <el-form-item label="">
          <el-date-picker v-model="dateRangetz[1]" type="date" value-format="yyyy-MM-dd" placeholder="结束时间"
            style="width: 130px !important;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="mark">
          <el-input v-model="queryParamsTz.mark" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryTz">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQueryTz">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form label-width="80px">
        <el-table v-loading="loading" style="overflow: auto; " height="400px" :data="tzList" border=""
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }" @selection-change="handleSelectionChangeTz"
          @row-click="handleClickTableRowD" ref="fileTableD">
          <el-table-column type="selection" width="55" align="center" :selectable="checkSelecttz" />
          <el-table-column label="拨款编号" align="center" prop="transId" width="200" />
          <el-table-column label="客户账号ID" align="center" prop="customerId" v-if="false" />
          <!--
          <el-table-column label="身份类型" align="center" width="100">
            <template slot-scope="scope">
              <span slot="reference" v-if="scope.row.deaname != null">
                <div style="float: left; margin-left: 10px;">经销商</div>
              </span>
              <span slot="reference" v-else-if="scope.row.cname != null">
                <div style="float: left; margin-left: 10px;">客户</div>
              </span>
              <span slot="reference" v-else>
                <div style="float: left; margin-left: 10px;color: red;">未识别</div>
              </span>

            </template>
          </el-table-column> -->
          <!-- <el-table-column label="帐号信息" align="center" prop="customerName" width="220" /> -->

          <el-table-column label="渠道名称" align="center">
            <template slot-scope="scope">
              <span slot="reference" v-if="scope.row.deaname != null">

                <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{ scope.row.deaname }}
                </div>
              </span>
              <span slot="reference" v-else-if="scope.row.cname != null">

                <div style="float: left; margin-left: 10px;">{{ scope.row.cname }}</div>
              </span>
              <span slot="reference" v-else>
                <div style="float: left; margin-left: 10px;color: red;">无关联名称</div>
              </span>
            </template>
          </el-table-column>
          <el-table-column label="调账类型" align="center" prop="operationType" width="80">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.tzlx" :value="scope.row.operationType" />
            </template>
          </el-table-column>
          <el-table-column label="客户id" align="center" prop="customerId" width="150" v-if="false" />
          <el-table-column label="调账时间" align="center" prop="operationTime" width="100">
            <template slot-scope="scope">
              <div>{{ parseTime(scope.row.operationTime, "{y}-{m}-{d}") }}</div>
            </template>
          </el-table-column>
          <el-table-column label="调账金额" align="right" prop="amount" width="80" />

          <el-table-column label="关联合同" align="center" prop="flag" width="130">
          </el-table-column>
          <el-table-column label="备注" align="left" prop="mark">
            <template slot-scope="scope">
              <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" :title="scope.row.mark">
                {{ scope.row.mark }}</div>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="totaltz > 0" :page-sizes="[10, 20, 30, 50, 100]" :total="totaltz"
          :page.sync="queryParamsTz.pageNum" :limit.sync="queryParamsTz.pageSize" @pagination="getListTz" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="tzClick">确 定</el-button>
        <el-button @click="tzcancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { getToken } from "@/utils/auth";
  import { listPayConItem } from "@/api/payment/PayContract";
  import { listbkitem } from "@/api/BankdetailsMain/bankdetails";
  import { listAdjust, listAdjustAll, listAdjustItem, updateAdjust } from "@/api/AdjustMain/adjust";
  import { listCustomerinfo } from "@/api/CustomerinfoMain/customerinfo";
  import {  listCustomerorder1, ImportCustomerorder, listCustomerorderAll, getCustomerorder, delCustomerorder, addCustomerorder, updateCustomerorder, insertxq, listCustomerorderItem, selectywy, updateqdc } from "@/api/CustomerorderMain/customerorder";
  import { listDealerAll, addDealersj, } from "@/api/DealerMain/dealer";
  // import { addAgreement, updateAgreement } from "@/api/resell/agreement"
  import { listAgreement, getAgreement, delAgreement, addAgreement, updateAgreement, Htcode } from "@/api/AgreementMain/agreement";
  import {getUserProfile, listuser, listJsy, listuser2, getUser2, listoutUser, listerdaiUser} from "@/api/system/user";
  import { done, TimeDate, GetMonA, GetMonB } from "@/api/public";
  import { listAgreementmoney } from "@/api/Agreementmoney/Agreementmoney"
  import { listCost } from "@/api/cost/cost";
  import { checkPermi, checkRole } from "@/utils/permission";  //权限判断
  import orderxx from '@/views/Mycomponents/OrderMain/orderxx';
  import ClipboardJS from 'clipboard';
  import SomeComponent from '@/views/wj/template/index.vue'
  import {listAllCustomList} from "@/api/resell/resellproject";
  import selectkh from "@/views/Mycomponents/selectkh.vue";
  import {listResellcustomerorder ,updateResellcustomerorder,listOrderItem} from "@/api/resell/resellcustomerorder";

  export default {
    dicts: ["sys_order_type", "sys_order_state", "ht_ddlx", "ht_skzh", "ht_xdms", "sys_yes_no", "ht_sjly", "ht_ddzq", "dea_type", "tzlx", "tz_type", "sys_order_fdbl", 'cost_pay_type', 'cost_type', "ht_skzh", "bank_type", "agreement_power"],
    name: "ContractManagement",
    components: {
      selectkh,
      orderxx,
      SomeComponent
    },
    data() {
      return {
        outallmoney: "0.00",
        inallmoney: "0.00",
        sdtype: false,
        testfile: null,
        bigfilelist: [],
        filearray: [],
        upload: {
          // 是否禁用上传
          isUploading: false,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/AgreementBig/AgreementBigfile/uploadfile",
          // 上传的文件列表
          fileList: []

        },
        allmoney: 0,
        //合作相关
        inuser: [],

        outuser: [],

        allfdbl: null,
        btype: null,//判断是否为添加虚拟合同进
        activeName: 'first',
        deaType: null, //实际渠道值 个人 企业
        zfjeshow: "0.00", //订单金额计算
        tzjeshow: "0.00", //调帐金额计算
        zgfdshow: "0.00",  //暂估返点计算
        fkjeshow: "0.00",  //返客金额
        fqjeshow: "0.00",  //返渠金额
        bkjeshow: "0.00",//银行打款金额
        bkdjce: "0.00",//打款差额
        xmmlshow: "0.00", //项目毛利计算
        sjmlshow: "0.00", //实际毛利计算
        mLlr: "0%",

        atype: null, //进页面时的类型，1表示添加，2修改

        ys: 0,//跳转过来的页数，用于加去时加载到对应页

        // 遮罩层
        loading: true,
        //关联订单
        loading1: true,
        //关联调帐
        loading3: true,


        //下拉对应参数
        deaOptionsa: [],
        jsyOption: [],//技术员
        BkOptions: [], //拨款人
        ywyOptions: [],//业务员
        XdOptions: [], //拨款人
        sh1Options: [],//审核人 1
        sh2Options: [], //审核人2

        // 费用管理表格数据-----------------
        costList: [],
        queryParamscost: {
          pageNum: 1,
          pageSize: 10,
          costContract: null,
        },

        //渠道客户对应的渠道-查询参数
        queryParamsdea: {
          pageNum: 1,
          pageSize: 9999,
          dtype: 2,
        },

        //订单数据弹窗选择相关-----------------------
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        openxq: false,
        deaval: {
          //分配时，传值的parm
          orderId: null,
          indirectPartnerId: null,
        },

        titleord: "",
        openord: false,
        // 总条数
        totalord: 0,
        dateRange: [],//订单时间过滤
        dateRangetz: [], //调帐时间过滤
        // 查询参数
        queryParamsord: {
          pageNum: 1,
          pageSize: 20,
          orderId: null,
          customer: null,
          customerId: null,
          serviceTypeCode: null,
          sourceType: null,
          status: null,
          orderType: null,
          amountAfterDiscount: null,
          officialAmount: null,
          measureId: null,
          paymentTime: null,
          currency: null,
          contractId: null,
          amountInfo: null,
          orderInfo: null,
          orderLineItems: null,
          userName: null,
          other1: null,
          other2: null,
          other3: null,
          other4: null,
          other5: null,
          ordselid: [],
          projectsId:null
        },
        customerorderListord: [],//选择订单弹窗数据列表
        //用于保存返点比例到订单表
        ddform: {},


        //合同实体类加载，这边不写会导致mod数据修改时不刷新，因为没有写restform赋值方法所以直接写这里了--------------------
        form2: {
          jeNfbl: "0.00",
          xmMl: null,
          sjMl: null,
          jeDk: null,
          jeBk: null,
          sfje: null,
          jeFk: null,
          jeFq: null,
          jeFdsj: null,
          jeFd: null,
          jejFdsj: null,
          jejFd: null,
          jeLrsj: null,
          jeLr: null,
          agrId: null,
          agrDate: null,
          deaId: null,
          realDea: null,
          customerId: null,
          customerIdHw: null,
          userId: null,
          ywyName: null,
          jsuserId: null,
          xduserId: null,
          bkuserId: null,
          agrType:null,
          bkUserId:null,
          xdUserId:null,

          agrDktt: null,
          agrDdzq: null,
          agrSkzh: null,
          agrSjly: null,
          agrXdms: null,
          agrDdlx: null,
          agrSfxk: null,
          orderIdItem: null, //获取数据显示到数组
          tzIdItem: null,

          gsname: null,//一级渠道
          sjname: null,//二级渠道
          khname: null,//客户员名称

          ordselid: [], //后台接收保存数据
          tzselid: [],
          qxList: [],

          cbj: null,
          qdj: null,
          khj:null,
          gwj:null,

          projectId:null,
          projectsId:null,
          accountId:null,
          projectName:null,
          accountName:null,
          agreementType:1,
          wecomName:null

        },
        //合同信息校验
        rulesht: {
          agrDate: [
            { required: true, message: "合同日期不能为空" },
          ],
          agrSjly: [
            { required: true, message: "商机来源不能为空" },
          ],
          agrDktt: [
            { required: true, message: "打款抬头不能为空" },
          ],
          agrSkzh: [
            { required: true, message: "收款帐号不能为空" },
          ],
          agrXdms: [
            { required: true, message: "下单模式不能为空" },
          ],
          agrDdlx: [
            { required: true, message: "订单类型不能为空" },
          ],
          agrDdzq: [
            { required: true, message: "订单周期不能为空" },
          ],
          agrSfxk: [
            { required: true, message: "是否新客不能为空" },
          ],
          khname: [
            { required: true, message: "客户名称不能为空" },
          ],
          sjname: [
            { required: true, message: "二级渠道不能为空" },
          ],
          gsname: [
            { required: true, message: "一级渠道不能为空" },
          ],
          projectName: [
            { required: true, message: "企业项目不能为空" },
          ],
          accountName: [
            { required: true, message: "华为账号不能为空" },
          ],
        },
        //查看权限
        queryqx: {
          htId: null,
        },
        myself: false,
        qxList: [],
        titleqx: "",
        openqx: false,
        qxform: {
          userId: null,
          moneyPro: null,
          moneyNumber: null,
          userType: null,
          type: null
        },
        selectuserid: "",
        selectusername: "",
        checklist: [{ value: "A", label: "订单管理" }, { value: "B", label: "拨款管理" }, { value: "C", label: "流程费用" }, { value: "D", label: "银行明细" }],

        //分配客户相关--------------------
        openkh: false,
        titlekh: "",
        khList: [],
        totalkh: 0,
        khid: [],
        khmc: [],
        // 查询参数
        queryParamsKh: {
          pageNum: 1,
          pageSize: 10,
          nickName: null,
          contactsName: null,
          phonenumber:null,
          createBy: null
        },

        //流程付款数据------------------
        // 付款申请表格数据
        PaymentList: [],
        queryParamsLc: {
          pageNum: 1,
          pageSize: 100,
          htId: null,
        },

        //实际渠道相关------------------
        title: "",
        open: false,
        //渠道添加弹窗时，隐藏显示
        sjbtshow: false,
        gsbtshow: false,
        //分配渠道相关
        openqd: false,
        titleqd: "",
        dealerList: [],
        deid: [],//分配选中的渠道
        dename: [],
        customerorderListItem: [],

        realDea: [], //实际渠道-选择客户时，赋值
        sjname: [], //实际名称-选择客户时，赋值

        qdval: {//分配时，传值的parm
          realDea: null,
          orderId: null,
        },
        totalqd: 0,
        // 查询参数
        queryParamsQd: {
          pageNum: 1,
          pageSize: 10,
          Dtype: 2,
          accountIn: null,
          deaName: null,

        },
        queryParamsHb: {
          pageNum: 1,
          pageSize: 10,
          userId: null,
          userName: null
        },
        // 实际渠道表单参数
        form: {
        },

        //实际渠道校验
        rules: {
          deaName: [
            { required: true, message: "渠道名称不能为空", trigger: "blur" },
          ],
          deaUser: [
            { required: true, message: "用户名不能为空", trigger: "blur" },
          ],
          deaCode: [
            { required: true, message: "渠道编码不能为空", trigger: "blur" },
          ],
          deaPeople: [
            { required: true, message: "联系人不能为空", trigger: "blur" },
          ],
          // deaPassword: [
          //   { required: true, message: "用户密码不能为空", trigger: "blur" },
          //   {
          //     min: 5,
          //     max: 20,
          //     message: "用户密码长度必须介于 5 和 20 之间",
          //     trigger: "blur",
          //   },
          // ],
          deaEmail: [
            {
              type: "email",
              message: "请输入正确的邮箱地址",
              trigger: ["blur", "change"],
            },
          ],
          deaTel: [
            { required: true, message: "手机号不能为空", trigger: "blur" },
            {
              pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
              message: "请输入正确的手机号码",
              trigger: "blur",
            },
          ],
        },

        //调帐记录相关-------------------------
        //用于保存调账备份和类型
        tzform: {},
        tzListItem: [],//选中后的调帐列表数据
        opentz: false,
        titletz: "",
        tzList: [],
        tzid: [],//分配选中的渠道
        totaltz: 0,
        // 查询参数
        queryParamsTz: {
          pageNum: 1,
          pageSize: 10,
          other1: null,
          tzdselid: [],
        },

        //银行明细查询参数-------------------------
        bkList: [],
        queryParamsBk: {
          pageNum: 1,
          pageSize: 30,
          agrid: null,
        },

        //下一条上一条查询对比
        searchparms: {
        },
        searchhtlist: [],
        searchdateRange: [],
        btntop: false,
        btnnext: false,
        customOption:[],
        choosekh: null
      };
    },

    created() {
      //进来时，加载初始数据
      // if (this.$route.query.atype != undefined) {
      //   this.getselList();//获取下拉数据信息
      //   this.ys = this.$route.query.ys;
      //   if (this.$route.query.atype == 1) {
      //     this.getUser();
      //     this.form2.agrSkzh = "1";
      //
      //     this.atype = 1;
      //     this.form2.bkuserId = "492";
      //     this.loading1 = false;
      //     this.loading3 = false;
      //
      //     //这里判断是否从拨款那边进来的，生成合同的方式要变，同时赋值到列表上 2023-06-29添加--生成虚拟合同
      //     if (this.$route.query.btype == 2) {
      //       this.btype = 2;
      //       this.form2.tzIdItem = this.$route.query.tid;
      //       let oitemid = this.form2.tzIdItem.split(','); //根据iditemid来绑定列表数据显示
      //       this.queryParamsTz.tzselid = oitemid;
      //       this.form2.deaId = this.$route.query.did;
      //       this.form2.gsname = this.$route.query.dname;;
      //
      //       this.activeName = "second";
      //     }
      //
      //     let x = {};
      //     x.userId = this.$store.state.user.userId;
      //     x.userName = this.$store.state.user.nickname;
      //     x.userType = "00";
      //     x.type = "0";
      //     x.moneyPro = 100;
      //     x.moneyNumber = 0;
      //     x.jsType = "0";
      //     this.qxList.push(x);
      //
      //
      //   }
      //   else {
      //
      //     //前面传过来的查询参数，用于上一下，下一页
      //     if (this.$route.query.searchparms != undefined) {
      //       this.searchparms = JSON.parse(this.$route.query.searchparms);
      //       this.searchdateRange = JSON.parse(this.$route.query.searchdateRange);
      //       this.btntop = true;
      //       this.btnnext = true;
      //     }
      //
      //     this.atype = 2;
      //
      //     if (this.$route.query.btype == 2) {
      //       this.btype = 2;
      //       this.activeName = "second";
      //     }
      //
      //     this.queryqx.htId = this.$route.query.aid;
      // //     //设置分润
      //     listAgreementmoney(this.queryqx).then(response => {
      //       this.qxList = response.data;
      //       this.jsallmoney();
      //     })
      //
      //     //查看合同
      //     getAgreementBig(this.$route.query.aid).then(response => {
      //       console.log(response);
      //       this.bkjeshow = "0.00";
      //
      //
      //       this.form2 = response.data;
      //
      //       this.form2.xmMl = (Number(this.form2.jeDk) - Number(this.form2.jeBk) + Number(this.form2.jeFd) - Number(this.form2.jeFk) - Number(this.form2.jeFq)).toFixed(2);
      //       this.form2.sjMl = this.form2.xmMl;
      //       this.qxList.forEach(item => {
      //
      //         if (item.userType == "05" || item.userType == "06") {
      //           this.form2.sjMl = (Number(this.form2.xmMl) - Number(item.moneyNumber)).toFixed(2);
      //         }
      //       })
      //
      //       if (response.data.agrType == "1") {
      //         this.sdtype = true;
      //       }
      //       this.bigfilelist = response.data.filelist;
      //       this.atype = 2;
      //       this.fdjs();
      //     });
      //
      //
      //   }
      // }
      // else {
      //   alert("访问异常");
      //   this.morelist();
      //   return;
      // }
      //
      this.getselList();//获取下拉数据信息
      console.log(this.$route.query.aid);
      console.log(this.$route.query.aid != undefined);
      if(this.$route.query.aid != null && this.$route.query.aid != undefined && this.$route.query.aid != ""){
        console.log(1111111);
        console.log(this.$route.query.aid);
        this.queryqx.htId = this.$route.query.aid;
        //设置分润
        listAgreementmoney(this.queryqx).then(response => {
          this.qxList = response.data;
          this.jsallmoney();
        })

        //查看合同
        getAgreement(this.$route.query.aid).then(response => {

          this.bkjeshow = "0.00";
          //查询合同对应的银行明细 2024-04-29
          let bkje = 0;
          this.queryParamsBk.bId = this.$route.query.aid;
          listbkitem(this.queryParamsBk).then(response => {
            this.bkList = response.rows;
            this.bkList.forEach(element => {
              bkje += Number(element.bSkje);
            });
            this.bkjeshow = bkje.toFixed(2);

          });

          this.form2 = response.data;

          this.form2.xmMl = (Number(this.form2.jeDk) - Number(this.form2.jeBk) + Number(this.form2.jeFd) - Number(this.form2.jeFk) - Number(this.form2.jeFq)).toFixed(2);
          this.form2.sjMl = this.form2.xmMl;
          this.qxList.forEach(item => {

            if (item.userType == "05" || item.userType == "06") {
              this.form2.sjMl = (Number(this.form2.xmMl) - Number(item.moneyNumber)).toFixed(2);
            }
          })

          this.atype = 2;
          //绑定订单列表
          if (this.form2.orderIdItem != null && this.form2.orderIdItem != "") {
            let oitemid = this.form2.orderIdItem.split(','); //根据iditemid来绑定列表数据显示
            this.queryParamsord.ordselid = oitemid;
            this.ImportClick();
          }
          else
            this.loading1 = false;


          /** 查询付款申请列表 -流程费用*/
          this.queryParamsLc.htId = this.$route.query.aid;
          listPayConItem(this.queryParamsLc).then(response => {
            this.PaymentList = response.rows;


            let fkje = 0;
            let fqje = 0;
            this.PaymentList.forEach(element => {
              if (element.payCostType == "返客" && element.payStatus == "2.0" && element.payEnd == "1")
                fkje += Number(element.payMoney);

              if (element.payCostType == "返渠" && element.payStatus == "2.0" && element.payEnd == "1") {
                fqje += Number(element.payMoney);
              }
            });

            this.fkjeshow = fkje.toFixed(2);
            this.fqjeshow = fqje.toFixed(2);
            // console.log(this.form2.xmMl)
            // console.log(this.form2.jeDk)

            if (Number(this.form2.xmMl) === 0 || Number(this.form2.jeDk) === 0)
              this.mLlr = "0%";
            else
              this.mLlr = ((Number(this.form2.sjMl) / Number(this.form2.jeDk)) * 100).toFixed(2) + "%";

          });


          //绑定调帐列表
          if (this.form2.tzIdItem != null && this.form2.tzIdItem != "") {
            let oitemid = this.form2.tzIdItem.split(','); //根据iditemid来绑定列表数据显示
            this.queryParamsTz.tzselid = oitemid;
            this.tzClick();
          }
          else
            this.loading3 = false;
        });
        this.dateRange[0] = GetMonA(3);
        this.dateRange[1] = GetMonB();
        this.dateRangetz[0] = "2023-01-01";//先暂定1月1
        //this.dateRangetz[0] = GetMonA(3);
        this.dateRangetz[1] = GetMonB();
      }

      //
      listuser().then(response => {
        this.inuser = response.rows;
      });
      listuser2().then(response => {
        this.outuser = response.rows;
      });
      // this.getOptionList()
      this.loading = false;
      this.loading3 = false;
      this.loading1 = false;

    },
    methods: {
      getOptionList(row) {
        listCustomList(row).then(response => {
          // console.log(response);
          this.customOption = response.rows;
        });
      },
      checkPermi, //引用权限检索
      //计算利润
      clickjs() {
        //必须转成int 才行，否则会计算不正确
        //为空时赋值0
        if (this.form2.cbj == null || this.form2.cbj == '')
          this.form2.cbj = "0.00";
        if (this.form2.qdj == null || this.form2.qdj == '')
          this.form2.qdj = "0.00";
        if (this.form2.khj == null || this.form2.khj == '')
          this.form2.khj = "0.00";

        //实际返点，结合华为
        const a = this.toFixed(Number(this.form2.jeDk) - Number(this.form2.jeBk));
        const b = this.toFixed(Number(a) + Number(this.form2.jeFdsj));

        const c = this.toFixed(Number(b) - Number(this.form2.jeFk));
        const d = this.toFixed(Number(c) - Number(this.form2.jeFq));
        const e = this.toFixed(Number(d) + Number(this.form2.jejFdsj));

        //业务员返点
        const b1 = this.toFixed(Number(a) + Number(this.form2.jeFd));
        const c1 = this.toFixed(Number(b1) - Number(this.form2.jeFk));
        const d1 = this.toFixed(Number(c1) - Number(this.form2.jeFq));
        const e1 = this.toFixed(Number(d1) + Number(this.form2.jejFd));
        // console.log(e);
        // console.log(d1);
        //this.form2.jeLrsj = e;
        this.form2.jeLrsj = "0.00";
        this.form2.jeLr = e1;
        //this.form2 = Object.assign({},this.form2);

        this.form2.xmMl = (Number(this.form2.jeDk) - Number(this.form2.jeBk) + Number(this.form2.jeFd) - Number(this.form2.jeFk) - Number(this.form2.jeFq)).toFixed(2);

        this.form2.sjMl = this.form2.xmMl;
        this.qxList.forEach(item => {
          if (item.userType == "05" || item.userType == "06") {
            this.form2.sjMl = (Number(this.form2.sjMl) - Number(item.moneyNumber)).toFixed(2);
          }
        })

        //this.fdjsclick();
        this.frml();
      },

      //计算值写到控制上 ordselid选中项赋值
      fdjs() {
        let eee = 0;//返点实际
        let oid = "";
        let xdje = 0;//下单金额
        let fdje = 0; //返点金额
        let gwjg = 0;//官网价
        let khjg = 0;//客户价
        this.customerorderListItem.forEach(element => {
          if (element.jeFdsj == null || element.jeFdsj == "")
            element.jeFdsj = 0;
          oid += element.orderId + ",";
          eee += Number(element.jeFdsj);
          xdje += Number(element.amountAfterDiscount);
          gwjg += Number(element.officialAmount);
          khjg += Number(element.amountAfterDiscount);

          if (element.jeFd != null && element.status != 4 && element.orderType != 4)
            fdje += (Number(element.amountAfterDiscount) * Number(element.jeFd)) / 100;

          if (this.form2.sjname == '' || this.form2.sjname == null) {
            this.form2.realDea = element.realDea;
            this.form2.sjname = element.realDeaName;

            this.form2.deaId = element.deaId;
            this.form2.gsname = element.deaname;

            this.form2.agrDktt = element.realDeaName;
          }
        });

        this.zfjeshow = xdje.toFixed(2);
        this.zgfdshow = fdje.toFixed(2);

        this.form2.jeFdsj = eee.toFixed(2);
        this.form2.gwj = gwjg.toFixed(2);
        this.form2.khj = khjg.toFixed(2);
        let oiditem = [];
        if (oid.length > 0) {
          oid = oid.substring(0, oid.length - 1);
          oiditem = oid.split(',');
        }
        this.form2.ordselid = oiditem;
        //this.form2.ordselid = this.queryParamsord.ordselid;
      },
      downloadfile(row) {
        console.log(row.fileUrl);
        var url = row.fileUrl;//"/profile/agreementfile/2024/07/03/1_20240703173512A001.jpg";///profile//2024/07/10/5_20240710140027A002.jpg
        this.$download.resource(url, false)
        // this.download('AgreementBig/AgreementBigfile/importTemplate', {
        // }, `${row.fileName}`)
      },
      //user_template_${new Date().getTime()}.xlsx
      handlefiledelete(index) {
        this.bigfilelist.splice(index, 1);
      },
      handleupRemove(item) {
        const index = this.upload.fileList.indexOf(item);
        if (index !== -1) {
          this.upload.fileList.splice(index, 1);
        }
        let indexa = 0;
        this.filearray.forEach((element) => {
          if (element == item.response.msg) {
            this.filearray.splice(indexa, 1);
          }
          indexa++;
        });

      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {

        console.log(response);
        if (response.code == "200") {
          this.bigfilelist.push(response.data);
        }
        console.log(this.bigfilelist);

        // if (response.code == "200") {
        //   this.filearray.push(response.msg);
        //   this.upload.fileList.push(file);
        // }
        // else {
        //   this.upload.fileList.push();
        //   this.$modal.msgError(response.msg);
        // }
      },
      frml() {
        this.qxList.forEach((item, index) => {
          if (item.userType == "00") {
            this.qxList[index].moneyPro = (this.qxList[index].moneyNumber * 100 / this.form2.sjMl).toFixed(2);
          }
          else {
            this.qxList[index].moneyPro = (this.qxList[index].moneyNumber * 100 / this.form2.xmMl).toFixed(2);
          }
        });
        this.jsallmoney();
      },
      frpro(index, type, pro) {
        if (type == "00") {
          this.qxList[index].moneyNumber = (this.form2.sjMl * pro / 100).toFixed(2);
        }
        else {
          this.qxList[index].moneyNumber = (this.form2.xmMl * pro / 100).toFixed(2);
        }
        this.jsallmoney();

      },
      frmoney(index, type, money) {
        if (type == "00") {
          this.qxList[index].moneyPro = (money * 100 / this.form2.sjMl).toFixed(2);
        }
        else {
          this.qxList[index].moneyPro = (money * 100 / this.form2.xmMl).toFixed(2);
        }
        this.jsallmoney();


      },
      jsallmoney() {
        this.inallmoney = "0.00";
        this.outallmoney = "0.00";
        this.qxList.forEach(item => {
          if (item.userType == "00") {
            this.inallmoney = (Number(this.inallmoney) + Number(item.moneyNumber)).toFixed(2);
          }
          else {
            this.outallmoney = (Number(this.outallmoney) + Number(item.moneyNumber)).toFixed(2);
          }

        });
      },
      radiochange(val) {
        if (val == 1) {
          this.ywyOptions = this.outuser;
        }
        else {
          this.ywyOptions = this.inuser;
        }
        this.qxform.userId = null;
      },
      delpow(row) {
        console.log(row);
        const removeIndex = this.qxList.findIndex(item => item.userName == row.userName)
        console.log(removeIndex);
        if (removeIndex !== -1) {
          this.qxList.splice(removeIndex, 1);
          this.jsallmoney();
        }

      },
      handleChangeuser(val) {
        this.selectuserid = val;
        this.selectusername = this.ywyOptions.find(option => option.userId == val).nickName;
        //console.log(this.selectusername);
      },
      submitqx() {
        const num = this.qxList.findIndex((item) => item.userId === this.qxform.userId);
        if (num != -1) {
          this.$modal.msgError("人员已存在")
        }
        else {
          this.qxform.userName = this.selectusername;
          let x = {};
          x.userId = this.qxform.userId;
          x.userName = this.qxform.userName;

          getUser2(this.qxform.userId).then(response => {

            x.userType = response.data.usertype;

          });
          x.userType = this.qxform.userType;
          x.moneyPro = "0";
          x.moneyNumber = "0";
          x.jsType = "0";
          this.qxList.push(x);
          console.log(this.qxList);
          this.openqx = false;
        }

      },
      cancelqx() {
        this.openqx = false;
      },
      handleDelete(index, row) {
        this.customerorderListItem.splice(index, 1);
        this.fdjs();
        this.clickjs();
      },
      handleDeletes(index, row) {
        this.$modal.confirm('是否删除按需订单"' + row.orderId + '"？').then(function () {
          return delCustomerorder(row.orderId);
        }).then(() => {
          //this.getList();
          this.customerorderListItem.splice(index, 1);
          this.fdjs();
          this.clickjs();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => { });
      },
      qxinadd() {
        this.titleqx = "添加合作伙伴";
        this.openqx = true;
        this.ywyOptions = this.inuser;
        this.qxform.userId = null;
        this.qxform.userName = null;
        this.qxform.moneyPro = null;
        this.qxform.moneyNumber = null;
        this.qxform.type = "0";
        this.qxform.jsType = "0";

      },

      //流程费用跳转查看
      handlefind(row) {
        let id = row.paySpnoid;
        let routeData = this.$router.resolve({ path: '/jsgl/paymentpage', query: { id: id } });
        window.open(routeData.href, '_blank');

      },
      //三个标签切换
      tbClick(tab, event) {
        //console.log(tab, event);
      },
      cancelHb(){
        this.form2.deaId = null;
      },
      //复制客户名称
      copy(cval) {
        var clipboard = new ClipboardJS(cval)
        clipboard.on('success', e => {
          // console.log('复制成功')
          // 释放内存
          this.$modal.msgSuccess("复制成功");
          clipboard.destroy()
        })
        clipboard.on('error', e => {
          // 不支持复制
          this.$modal.msgWarning("该浏览器不支持自动复制");
          //console.log('该浏览器不支持自动复制')
          // 释放内存
          clipboard.destroy()
        })
      },

      findcost: function (atype, row) {
        var rid = "";
        if (row != null)
          rid = row.costId;
        let routeData = this.$router.resolve({ path: '/jsgl/costs', query: { atype: atype, did: null, aid: rid, } });
        window.open(routeData.href, '_blank');
      },

      //获取当前登录业务员信息
      getUser() {
        getUserProfile().then(response => {
          this.form2.userId = response.data.userId.toString();
          this.form2.ywyName = response.data.nickName
        });
      },
      // 表单重置
      reset() {
        this.form = {

        };
        this.resetForm("form");
      },
      //保留两位，不足补位
      toFixed(num) {
        return (Math.round(num * 100) / 100).toFixed(2);
      },
      /** 查询客户列表 下拉绑定*/
      getselList() {

        //2024-04-29 注销，这个好像没用到现在。包含查询参数和变量定义
        // listDealerAll(this.queryParamsdea).then((response) => {
        //   this.deaOptionsa = response.rows;
        // });

        //绑定技术员
        listJsy().then((response1) => {
          this.jsyOption = response1.rows;
          this.XdOptions = response1.rows;
        });
        //绑定业务员
        listuser(this.queryParamsUser).then(response => {
          this.ywyOptions = response.rows;
          this.BkOptions = response.rows;

          this.sh1Options = response.rows;
          this.sh2Options = response.rows;

          this.loading = false;
        });
      },

      /** 弹窗查询订单列表列表 */
      getListord() {
        //判断表格列是否显示。测试管用
        this.loading = true;
        listResellcustomerorder(this.addDateRange(this.queryParamsord, this.dateRange)).then(response => {
          this.customerorderListord = response.rows;
          this.totalord = response.total;
          this.loading = false;

        });
      },

      plusOrMinus(values) {
        let newValue;
        if (!(/[^0-9.-]/g.test(values))) {
          newValue = values.replace(/[^\-\d.]/g, '').replace(/\-{2,}/g, '-').replace(/\-{2,}/g, '-').replace(/^\./g, '')
            .replace(/\.{2,}/g, '.')
            .replace('.', '$#$')
            .replace(/\./g, '')
            .replace('$#$', '.');
          if (newValue.toString().indexOf('.') > 0 && Number(newValue.toString().split('.')[1].length) > 2) {
            newValue = parseInt(parseFloat(newValue) * 100) / 100;
          }
          if ((newValue.toString().split('-').length - 1) > 1) {
            newValue = parseFloat(newValue) || '';
          }
          if ((newValue.toString().split('-').length) > 1 && newValue.toString().split('-')[0].length > 0) {
            newValue = parseFloat(newValue) || '';
          }
          if (newValue.toString().length > 1 && (newValue.toString().charAt(0) === '0' || (newValue.toString().length > 2 && newValue.toString().charAt(0) === '-' && newValue.toString().charAt(1) === '0' && newValue.toString().charAt(2) !== '.')) && newValue.toString().indexOf('.') < 1) {
            newValue = parseFloat(newValue) || '';
          }
          // 判断整数位最多为9位
          if (newValue.toString().indexOf('.') > 0 && Number(newValue.toString().split('.')[0].length) > 9) {
            newValue = `${newValue.toString().substring(0, 9)}.${newValue.toString().split('.')[1]}`;
          } else if (newValue.toString().indexOf('.') < 0 && Number(newValue.toString().split('.')[0].length) > 9) {
            newValue = newValue.toString().substring(0, 9);
          }
        } else {
          newValue = values.replace(/[^0-9.-]/g, '');
        }
        return newValue;
      },
      // 额外费用校验输入正负数， 保留2位小数 调用公共方法
      RestrictedMoney(values) {
        return this.plusOrMinus(values.toString());
      },
      // 结合change事件对失去焦点进行判断，防止输入一些无效值
      materielExtraCostChange(item, type) {
        // 防止删除为空
        if (!item) {
          item = '0.00';
        }
        // 一些错误金额输入的判断
        if (item.toString().indexOf('.') > 0 && Number(item.toString().split('.')[1].length) < 1) {
          item = item.toString().split('.')[0];
        }
        // 一些错误金额输入的判断
        if (!item || item === '-' || item === '-0') {
          item = '0.00';
          return;
        }
        item = parseFloat(item).toFixed(2);
        if (type == 1)
          this.form2.jeDk = item;
        if (type == 2)
          this.form2.jeBk = item;
        if (type == 3)
          this.form2.jeFk = item;
        if (type == 4)
          this.form2.jeFq = item;
        if (type == 5)
          this.form2.jeFd = item;
        if (type == 6)
          this.form2.jeFdsj = item;
        if (type == 7)
          this.form2.jejFdsj = item;
        if (type == 8)
          this.form2.jejFd = item;
        this.form2.xmMl = (Number(this.form2.jeDk) - Number(this.form2.jeBk) + Number(this.form2.jeFd) - Number(this.form2.jeFk) - Number(this.form2.jeFq)).toFixed(2);

        this.form2.sjMl = this.form2.xmMl;
        this.qxList.forEach(item => {
          if (item.userType == "05" || item.userType == "06") {
            this.form2.sjMl = (Number(this.form2.sjMl) - Number(item.moneyNumber)).toFixed(2);
          }
        })
      },
      /** 返回列表 */
      morelist() {
        this.$router.push(
          {
            path: '/zsgl/agreement',
            methods: 'post',
            query: {
              ys: this.ys,
            }
          })
      },
      /** 新增按钮操作 */
      adddd() {
        if (this.form2.khname == "" || this.form2.khname == null) {
          this.$modal.msgWarning("请先选择对应客户");
        }
        else {

          this.queryParamsord.ordselid = null;
          this.openord = true;
          this.titleord = "订单选择弹窗";
          // this.queryParamsord.customerId = this.form2.customerIdHw;
          this.resetQuery();
        }
      },
      changeJG(scope){
        console.log(scope)
        if(scope.row.qdj > scope.row.khj){
          this.customerorderListItem[scope.$index].qdj = scope.row.khj;
        }
        if(scope.row.cbj > scope.row.qdj && scope.row.qdj != null){
          this.customerorderListItem[scope.$index].cbj = scope.row.qdj;
        }
        let qdjg = 0;//渠道价
        let cbjg = 0;//成本价
        this.customerorderListItem.forEach(element => {
          qdjg += Number(element.qdj);
          cbjg += Number(element.cbj);
        })
        this.form2.cbj = cbjg.toFixed(2);
        this.form2.qdj = qdjg.toFixed(2);

      },
      ImportClick(row) {
        //判断是否选择了订单
        // console.log(this.customerorderListItem);
        const eee = this.queryParamsord.ordselid; //选中的订单
        if (eee.length < 1) {
          this.$modal.msgWarning("请至少选择一条数据");

          return;
        }

        //这两个一样，忘记为什么要写这样了？
        if (this.atype == 2) {

          listOrderItem(this.queryParamsord).then(response => {
            if (this.customerorderListItem.length > 0) {
              response.rows.forEach(el1 => {
                el1.gwj = el1.officialAmount;
                el1.khj = el1.amountAfterDiscount;
                this.customerorderListItem.push(el1);
              });
            }
            else{
              this.customerorderListItem = response.rows;
              this.customerorderListItem[0].gwj = response.rows[0].officialAmount;
              this.customerorderListItem[0].khj = response.rows[0].amountAfterDiscount;
            }

            //数组对象去重
            let uniqueDataList = this.customerorderListItem.filter((item, index, self) => {
              // 返回第一个匹配项的索引，用于判断当前项是否为第一个匹配项
              const firstIndex = self.findIndex((obj) => obj.orderId === item.orderId);
              // 如果当前项是第一个匹配项，则保留，否则过滤掉
              return index === firstIndex;
            });
            this.customerorderListItem = uniqueDataList;

            // this.loading = false;
            this.loading1 = false;
            this.openord = false;
            this.fdjs();
          });
        }
        else {

          listOrderItem(this.queryParamsord).then(response => {
            if (this.customerorderListItem.length > 0) {
              response.rows.forEach(el1 => {
                el1.gwj = el1.officialAmount;
                el1.khj = el1.amountAfterDiscount;
                console.log(el1);
                this.customerorderListItem.push(el1);
              });
            }
            else{
              response.rows.forEach(el1 => {
                el1.gwj = el1.officialAmount;
                el1.khj = el1.amountAfterDiscount;
              });
              this.customerorderListItem = response.rows
              console.log(this.customerorderListItem);
            }


            //数组对象去重
            let uniqueDataList = this.customerorderListItem.filter((item, index, self) => {
              // 返回第一个匹配项的索引，用于判断当前项是否为第一个匹配项
              const firstIndex = self.findIndex((obj) => obj.orderId === item.orderId);
              // 如果当前项是第一个匹配项，则保留，否则过滤掉
              return index === firstIndex;
            });
            this.customerorderListItem = uniqueDataList;

            this.loading = false;
            this.loading1 = false;
            this.openord = false;
            this.fdjs();
          });
        }
      },
      changedate(val) {
        this.form2.agrId = 'ZS' + val.split("-").join("") + '-' + done(3, 9);
      },
      //订单取消
      cancelord() {
        this.openord = false;
        this.reset();
      },
      // 订单弹窗多选框选中数据1
      handleSelectionChange1(selection) {
        this.queryParamsord.ordselid = selection.map(item => item.orderId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 订单搜索按钮操作 */
      handleQuery() {
        this.queryParamsord.pageNum = 1;
        // this.queryParamsord.customerId = this.form2.customerId;
        this.queryParamsord.projectsId = this.form2.wecomName;
        this.getListord();
      },
      /** 订单重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 设置价格提交按钮 */
      submitForm2() {
        console.log(this.form2)

        this.form2.qxList = this.qxList;
        console.log(this.customerorderListItem)
        // this.form2.filelist = this.bigfilelist;
        this.tzListItem.forEach(element => {
          this.tzform.transId = element.transId;
          this.tzform.mark = element.mark;
          this.tzform.applx = element.applx;
          var a = 1;
          if (this.tzform.applx != null) {
            a = 2;
          }
          if (this.tzform.mark != null) {
            a = 2;
          }
          if (a == 2) {
            updateAdjust(this.tzform).then(response => {
            });
          }
        });

        // //保存返点比例到订单表中
        this.customerorderListItem.forEach(element => {
          if (element.jeFd != null) {
            this.ddform.orderId = element.orderId;
            this.ddform.jeFd = element.jeFd;
            this.ddform.gwj = element.gwj;
            this.ddform.cbj = element.cbj;
            this.ddform.qdj = element.qdj;
            this.ddform.khj = element.khj;
            updateResellcustomerorder(this.ddform).then(response => {
            });
          }
        });

        this.$refs["form2"].validate(valid => {
          if (valid) {
            if (this.atype == 2) {
              updateAgreement(this.form2).then(response => {
                this.$modal.msgSuccess("修改成功");
                if (this.$store.state.user.userId == 118)
                  this.morelist();
              });
            } else {

              addAgreement(this.form2).then(response => {
                this.$modal.msgSuccess("保存成功");
                this.atype = 2;
                if (this.$store.state.user.userId == 118)
                  this.morelist();
              });
            }

          }
        });
        //this.$store.dispatch("htxg/agreementht", this.$route);
      },
      /** 选择客户相关事件 */
      showkh() {
        this.openkh = true;
        this.titlekh = "选择客户";
        this.getListKh();
      },
      khcancel() {
        this.openkh = false;
      },
      /** 搜索按钮操作 */
      handleKhQuery() {
        this.getListKh();
      },
      /**分配客房窗口重置 */
      resetQueryKh() {
        // this.queryParamsKh.createBy = null
        this.resetForm("queryFormKh");
        this.handleKhQuery();
      },
      /** 分配客户多选框选中数据1 客户*/
      handleSelectionChangeKh(selection) {
        //获取数组最后一条数据
        const last = selection[selection.length - 1];
        //如果表格选择的数组长度大于1条，先清空数组再插入刚刚取出的最后一条
        if(selection.length > 1){
          this.$refs.fileTableA.clearSelection();
          this.$refs.fileTableA.toggleRowSelection(last, true);
        }
        //将最后一个选择的客户赋值给变量
        this.choosekh = last
        // this.khid = selection.map(item => item.customerIdHw)
        // this.khmc = selection.map(item => item.customer)
        //
        // this.deid = selection.map(item => item.deaId), //归属渠道element.realDea;
        //   this.dename = selection.map(item => item.deaName), //归属名称
        //
        //   this.realDea = selection.map(item => item.realDea), // realDea;
        //   this.sjname = selection.map(item => item.realDeaName), //实际名称
        //
        //   this.single = selection.length !== 1
        // this.multiple = !selection.length
      },
      /** 查询分配客户列表 */
      getListKh() {
        listAllCustomList(this.queryParamsKh).then(response => {
          this.totalkh = response.total;
          this.khList = response.rows;
        });
      },
      /** 分配客户操作 */
      khClick() {
        // if (this.khid.length > 1) {
        //   this.$modal.msgWarning("只能选择一个客户");
        //   return;
        // }
        // this.form2.customerId = this.khid[0];
        // this.form2.khname = this.khmc[0];
        //
        // this.form2.deaId = this.deid[0];
        // this.form2.gsname = this.dename[0];
        // //没有实际渠道，取归属渠道
        // if (this.realDea == '' || this.realDea == null) {
        //   this.form2.realDea = this.deid[0];
        //   this.form2.sjname = this.dename[0];
        // }
        // else {
        //   this.form2.realDea = this.realDea[0];
        //   this.form2.sjname = this.sjname[0];
        // }
        console.log(this.choosekh.remark)
        if(this.choosekh.remark == '' || this.choosekh.remark == null){
          this.$modal.msgWarning("当前选择客户还未绑定企业项目")
        }
        else {
          this.form2.projectsId = this.choosekh.contactsJob
          this.form2.khname = this.choosekh.nickName
          this.form2.projectName = this.choosekh.remark
          this.form2.accountName = this.choosekh.updateBy
          this.form2.accountId = this.choosekh.contactsName
          this.form2.wecomName = this.choosekh.wecomName
          this.khcancel();
        }
        // this.khcancel();
      },

      /****渠道操作相关 */
      showsjqd(type) {

        if (type == 1) {
          //表示实际渠道
          this.sjbtshow = true;
          this.gsbtshow = false;
          this.titleqd = "选择二级渠道";
          this.myself = true;
          this.queryParamsHb.userId = this.form2.deaId;
        }
        else {
          //表示归属渠道
          this.sjbtshow = false;
          this.gsbtshow = true;
          this.titleqd = "选择一级渠道";
          this.myself = false;
          this.queryParamsHb.userId = null;
        }

        this.queryParamsHb.nickName = null;
        this.openqd = true;

        this.getListDea();
      },
      /** 查询分配渠道列表 */
      getListDea() {
        this.loading = true;
        // listDealerAll(this.queryParamsQd).then((response) => {
        //   this.dealerList = response.rows;
        //   this.totalqd = response.total;
        //   this.loading = false;
        //
        // });
        listerdaiUser(this.queryParamsHb).then(response => {
          this.dealerList = response.rows;
          let i = 0;
          if(this.queryParamsHb.userId != null){
            this.dealerList.forEach(element => {
              if (element.userId == this.queryParamsHb.userId) {
                this.dealerList.splice(i, 1);
                this.dealerList.unshift(element);
                return
              }
              i = i + 1;
            })

          }
          this.totalqd = response.total;
          this.loading = false;
          }
        );
      },
      // 分配弹窗多选框选中数据1 渠道
      handleSelectionChangeQd(selection) {
        this.deid = selection.map(item => item.userId)
        this.dename = selection.map(item => item.nickName)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      cancelqd() {
        this.openqd = false;
        this.reset();
      },
      /** 分配渠道搞操作 */
      qdClick() {
        if (this.deid.length > 1) {
          this.$modal.msgWarning("只能选择一个渠道");

          return;
        }
        this.form2.realDea = this.deid[0];
        this.form2.sjname = this.dename[0];
        this.cancelqd();
      },
      handleMyself(){
        this.form2.realDea = this.form2.deaId;
        this.form2.sjname = this.form2.gsname;
        this.cancelqd();
      },
      gsqdClick() {
        if (this.deid.length > 1) {
          this.$modal.msgWarning("只能选择一个渠道");
          return;
        }

        this.form2.deaId = this.deid[0];
        this.form2.gsname = this.dename[0];
        this.cancelqd();
      },
      /**分配渠道窗口重置 */
      resetQueryQd() {
        this.resetForm("queryFormQd");
        this.handleQdQuery();
      },
      /** 搜索按钮操作 */
      handleQdQuery() {
        this.getListDea();
      },

      //复制返点金额
      copyfd() {
        this.form2.agrDktt = this.form2.sjname;
      },
      /** 新增实际渠道按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加渠道信息";
        this.deaType = 1;

        const tsj = TimeDate();
        this.form.deaCode = 'QD' + tsj.split("-").join("") + '-' + done(3, 9);

      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 实际渠道提交按钮 */
      submitForm() {
        this.form.deaType = this.deaType;
        this.$refs["form"].validate((valid) => {
          if (valid) {
            addDealersj(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;

            });
          }
        });
      },
      /** 查看订单情况 */
      xqtc(row) {
        this.openxq = true;
        this.deaval.orderId = row.orderId;
        this.deaval.indirectPartnerId = row.indirectPartnerId;
      },
      /** 订单选择列表，判断是否与当前合同编号一致，不可选
  * row：当前行数据
  * index：当前第几位
  */
      checkSelect(row, index) {
        let isChecked = true;
        if (row.flag != null && row.flag != '' && row.flag != this.form2.agrId) { // 判断里面是否存在某个参数
          isChecked = false
        } else {
          isChecked = true
        }
        return isChecked
      },
      handleClickTableRow(row, event, column) {
        if (row.flag != null && row.flag != '' && row.flag != this.form2.agrId) { // 判断里面是否存在某个参数

        } else {
          this.$refs.fileTable.toggleRowSelection(row);
        }

      },
      handleClickTableRowA(row, event, column) {
        this.$refs.fileTableA.toggleRowSelection(row);
      },
      handleClickTableRowB(row, event, column) {
        this.$refs.fileTableB.toggleRowSelection(row);
      },


      /** 选择调帐相关事件 */
      addtz() {
        if (this.form2.gsname == "" || this.form2.gsname == null) {
          this.$modal.msgWarning("请先选择关联渠道");
        }
        else {
          this.queryParamsTz.tzselid = null;
          this.queryParamsTz.other1 = this.form2.deaId;
          this.opentz = true;
          this.titletz = "选择调帐记录";
          this.getListTz();
        }
      },
      /** 查询调帐列表 */
      getListTz() {

        listAdjustAll(this.addDateRange(this.queryParamsTz, this.dateRangetz)).then(response => {
          // listAdjust(this.queryParamsTz).then(response => {
          this.tzList = response.rows;
          this.totaltz = response.total;

        });
      },
      tzcancel() {
        this.opentz = false;
      },
      /** 搜索按钮操作 */
      handleQueryTz() {
        this.getListTz();
      },
      /**分配合同窗口重置 */
      resetQueryTz() {
        this.resetForm("queryFormTz");
        this.handleQueryTz();
      },
      /** 分配调帐多选框选中数据1 */
      handleSelectionChangeTz(selection) {
        this.queryParamsTz.tzselid = selection.map(item => item.transId)

        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      handleClickTableRowD(row, event, column) {
        this.$refs.fileTableD.toggleRowSelection(row);
      },
      checkSelecttz(row, index) {
        let isChecked = true;
        if (row.flag != null && row.flag != '' && row.flag != this.form2.agrId) { // 判断里面是否存在某个参数
          isChecked = false
        } else {
          isChecked = true
        }
        return isChecked
      },
      /** 分配调帐确认操作 */
      tzClick() {
        //判断是否选择了订单
        const eee = this.queryParamsTz.tzselid; //选中的订单

        if (eee.length < 1) {
          this.$modal.msgWarning("请至少选择一条数据");

          return;
        }
        //判断表格列是否显示。测试管用

        this.loading3 = true;

        listAdjustItem(this.queryParamsTz).then(response => {
          if (this.tzListItem.length > 0) {
            response.rows.forEach(el1 => {
              this.tzListItem.push(el1);
            });
          }
          else
            this.tzListItem = response.rows;

          //数组对象去重
          let uniqueDataList = this.tzListItem.filter((item, index, self) => {
            // 返回第一个匹配项的索引，用于判断当前项是否为第一个匹配项
            const firstIndex = self.findIndex((obj) => obj.transId === item.transId);
            // 如果当前项是第一个匹配项，则保留，否则过滤掉
            return index === firstIndex;
          });
          this.tzListItem = uniqueDataList;

          this.loading3 = false;
          this.Tzjx();
        });
        this.tzcancel();
      },
      // 调帐删除行
      handleDeletetz(index, row) {
        this.tzListItem.splice(index, 1);
        this.Tzjx();
      },
      //调帐实体类赋值选中行
      Tzjx() {
        let oid = "";
        let tzje = 0;
        this.tzListItem.forEach(element => {

          oid += element.transId + ",";
          //这里如果是回收的，要减去金额
          if (element.operationType == "SOURCE_OPERATION_BERETRIEVE")
            tzje = tzje - Number(element.amount);
          else
            tzje += Number(element.amount);
        });
        let oiditem = [];
        if (oid.length > 0) {
          oid = oid.substring(0, oid.length - 1);
          oiditem = oid.split(',');
        }
        this.tzjeshow = tzje.toFixed(2);
        this.form2.tzselid = oiditem;

      },
      //跳转到银行明细页面 - 添加 -修改 传类型参数
      findbk: function (atype, row) {
        var rid = "";
        if (row != null)
          rid = row.bId;
        var bids = [];
        bids.push(rid);

        let routeData = this.$router.resolve({ path: '/jsgl/bankdetailsht', query: { atype: atype, aid: bids, } });
        window.open(routeData.href, '_blank');
      },
      //上一条按钮
      topht() {
        listAgreement(this.addDateRange(this.searchparms, this.searchdateRange)).then(response => {

          this.searchhtlist = response.rows;

          let sl = this.searchhtlist.length;

          let i = 0;
          this.searchhtlist.forEach(element => {
            i++;
            if (element.agrId == this.$route.query.aid) {

              if (i <= sl) {
                if (i - 1 > 0) {

                  let tzid = this.searchhtlist[i - 2].agrId;
                  // alert(tzid);
                  window.close();
                  let routeData = this.$router.resolve({
                    path: '/htxg/agreementbight', query: {
                      atype: 2, did: null, aid: tzid, ys: this.searchparms.pageint, searchparms: JSON.stringify(this.searchparms), searchdateRange: JSON.stringify(this.searchdateRange)
                    }
                  });
                  window.open(routeData.href, '_blank');
                }
                else {
                  let ps = this.searchparms.pageSize; //每页数
                  let pn = this.searchparms.pageNum; //当前页
                  let pys = response.total / ps; //总页数
                  if (pn != 1) {
                    this.searchparms.pageNum = pn - 1;
                    listAgreement(this.addDateRange(this.searchparms, this.searchdateRange)).then(response => {
                      this.searchhtlist = response.rows;
                      // console.log(this.searchhtlist);
                      let sl = this.searchhtlist.length;

                      let tzid = this.searchhtlist[sl - 1].agrId;

                      window.close();
                      let routeData = this.$router.resolve({
                        path: '/htxg/agreementbight', query: {
                          atype: 2, did: null, aid: tzid, ys: this.searchparms.pageint, searchparms: JSON.stringify(this.searchparms), searchdateRange: JSON.stringify(this.searchdateRange)
                        }
                      });
                      window.open(routeData.href, '_blank');
                    });
                  }
                  else {
                    this.$modal.msgSuccess("未查询到上一条数据！");
                  }

                }
              }


            }
          });
        });

      },
      //下一条按钮
      nextht() {

        listAgreement(this.addDateRange(this.searchparms, this.searchdateRange)).then(response => {

          this.searchhtlist = response.rows;


          let sl = this.searchhtlist.length;
          //  console.log(sl);
          let i = 0;
          this.searchhtlist.forEach(element => {
            i++;
            if (element.agrId == this.$route.query.aid) {
              // console.log(element.agrId);
              if (i < sl) {
                // console.log(i);
                // console.log(this.searchhtlist[i].agrId);
                let tzid = this.searchhtlist[i].agrId;
                window.close();
                let routeData = this.$router.resolve({
                  path: '/htxg/agreementbight', query: {
                    atype: 2, did: null, aid: tzid, ys: this.searchparms.pageint, searchparms: JSON.stringify(this.searchparms), searchdateRange: JSON.stringify(this.searchdateRange)
                  }
                });
                window.open(routeData.href, '_blank');
              }
              else {
                //这里要判断有没有下一页数据，有的话，查询出来再执行上面的方法
                // console.log(this.searchparms);
                // console.log(response.total);
                let ps = this.searchparms.pageSize; //每页数
                let pn = this.searchparms.pageNum; //当前页
                let pys = response.total / ps; //总页数
                if (pn < pys) {
                  this.searchparms.pageNum = pn + 1;
                  listAgreement(this.addDateRange(this.searchparms, this.searchdateRange)).then(response => {
                    this.searchhtlist = response.rows;
                    // console.log(this.searchhtlist);
                    let sl = this.searchhtlist.length;

                    let tzid = this.searchhtlist[0].agrId;
                    window.close();
                    let routeData = this.$router.resolve({
                      path: '/htxg/agreementbight', query: {
                        atype: 2, did: null, aid: tzid, ys: this.searchparms.pageint, searchparms: JSON.stringify(this.searchparms), searchdateRange: JSON.stringify(this.searchdateRange)
                      }
                    });
                    window.open(routeData.href, '_blank');

                  });
                }
                else {
                  this.$modal.msgSuccess("未查询到下一条数据！");
                }
              }
            }
          });
        });

      },
    },

  };
</script>
<style>
  .el-table th.gutter {
    display: table-cell !important;
    /* 解决表头线未对齐 */
  }

  .jeclass .el-input__inner {
    text-align: right;
  }



  .hide-upload-list .el-upload-list {
    display: none;
  }
  .clicktable{
    .el-table-column--selection.is-leaf .el-checkbox {
      display: none;
    }
  }
</style>
<style lang="scss" module>
  .ElDialog {
    :global .el-dialog__body {
      padding: 1px !important;
    }
  }
</style>
